In ASP.Net, we previously wrote this code for authorization :
public class PageBase : System.Web.UI.Page
{
protected override void OnInit(System.EventArgs e)
{
string CurrentPath = HttpContext.Current.Request.Url.AbsolutePath.ToLower();
//Check If User Access to this Path
if(WebUser.Access(CurrentPath) == false)
{
Reposponse.Redirect("Loagin.aspx");
}
}
}
And WebUser
is a Session that Contains user data:
public User WebUser
{
get
{
if (HttpContext.Current.Session["User"] != null)
{
return (User)HttpContext.Current.Session["User"];
}
else
{
HttpContext.Current.Response.Redirect("Login.aspx", true);
return null;
}
}
}
we inherit all page from PageBase
.
Now if I want to write similar code using MVC
where I can write a code that run on every request?
Thank