Reputation: 73
I want to security of some pages. These were the methods I used mvc 5 and before.
@{
if(ViewBag.SessionId == null)
{
Response.Redirect("~/Home/Index");
}
}
But this way doesn't way now.I could not find a solution in my research. .What should I do now ?
Upvotes: 3
Views: 4070
Reputation: 13167
You can replace it by:
@{
if (ViewBag.SessionId == null)
{
Context.Response.Redirect(Url.Content("~/Home/Index"));
}
}
As Shyju noted, probably it is better to handle such redirection on the controller or even filter level. Another improvement could be a replacement Url.Content("~/Home/Index")
to Url.Action("Index", "Home")
in case when ~/Home/Index
points to the HomeController.Index
action.
Upvotes: 2