Response.Redirect doesn't run using Razor in View

280 views Asked by At
@{
    if (Session["LoginType"] == null)
    {
       Response.Redirect("~/Account/Login", true);
    }

}

If the Session expires, the Session["LoginType"] becomes null. I can catch that. But the next line to redirect to the login page again, doesn't work. Yellow code line in break mode just stops on it, then moves on to next lines of code (that gives an error because the Session["LoginType"] is null.

Any ideas? Am I coding this wrong? Not really an expert at this MVC/Razor stuff.

1

There are 1 answers

1
Craig W. On BEST ANSWER

You should be performing this type of logic in the controller rather than the view.