I'm modifying an asp.net MVC application where Razor is used in the .cshtml. In the header is a call to the function "RendoWelcomeMessage()". This calls a function in a script on the same page. Normally, it displays the user's name. If the session has timed out, it displays a message saying to login. I need to change it so that if the session times out it redirects to the login page. The code below doesn't work. It seems to skip or ignore the redirect and just returns the message. How do I get the redirect to work?
Here's the call to the function in the HTML header:
<header>
<div class="content-wrapper">
<div class="float-right" style="font-size: 10pt;">
<b>@RenderWelcomeMessage()</b>@Html.Raw(@RenderUser())
</div>
</div>
</header>
Here's the function:
@functions
{
public string RenderWelcomeMessage()
{
string welcomeMessage = "Please Log In";
try
{
welcomeMessage = Session["CurrLoggedUser"] == null ? "Please Log In" : "Welcome: ";
}
catch (Exception ex)
{
Response.Redirect("~/Account/Login");
//return "Please Log In";
}
return welcomeMessage;
}
}
It's definitely hitting the part in the catch, but it's behaving as if I'd never added the response.redirect.