Changing ASP.NET Forms Authorization Redirection
ASP.NET makes it easy to configure Forms Authentication and Authorization, including automatically redirecting you to the login page when necessary. The problem is that it also redirects authenticated users to the login page when they attempt to access pages that they are not authorized to access. This gives you the opportunity to login as someone else, and then be automatically redirected back to the page you originally attempted to access. But that may not be the behavior you want for authenticated users -- do your users really have multiple logins and do they understand why they end up back at the login page? Instead, I want my authenticated users to be redirected to some other page that tells them they do not have access, and possibly gives them a way to contact an administrator. So here's the code that you need to put in your Global.asax file:
protected void Application_AuthorizeRequest(Object sender, EventArgs e) {
if (this.Request.Path.ToUpper().EndsWith("LOGIN/DEFAULT.ASPX") && this.Request.IsAuthenticated) {
this.Response.Redirect("~/Login/Unauthorized.aspx");
}
}
Note that this will prevent any users with multiple logins from being able to switch their login -- the solution for them is to first logout, or close and reopen the browser.