Redirect unauthorized users asp net
I'm working on a simple website in asp.net. I would like to restric access
to the side, so that only users in a specific AD group is allowed. I have
done that and it is working fine. But when a user that's not in the AD
group tries to access the site, they are getting a promt. How do I
redirect the unauthorized user to a custom page, instead of they getting
the login promt?
Below is my web.config. The lowest part of the code, is something i tried
but did not work.
<location path="AccessDenied.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
I have added this to the Global.asax.cs:
protected void Application_EndRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Response.Status.StartsWith("401"))
{
HttpContext.Current.Response.ClearContent();
Server.Execute("AccessDenied.aspx");
}
}
Any ideas ?
No comments:
Post a Comment