I have an MVC website in which access is based on various Roles. Once a user logs into the system they can see navigation to the pages for which they are authorized. However
To redirect-unauthorized-page-access-Asp.net C# -to-custom-view
protected void Page_Load(object sender, EventArgs e)
{
try
{
txtUsername.Focus();
if (!IsPostBack)
{
if (Request.IsAuthenticated && !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
{
Response.Redirect("UnauthorizedAccess.aspx", false);
return;
}
Session.Clear();
Session.Abandon();
}
}
catch (Exception ex)
{
this.errLogin.Text = ex.Message;
}
}
2)create UnauthorizedAccess.aspx
Unauthorized
Sorry, you are not authorized to access this page
Back to Home