R
rote
I'm using ASP.NET 2.0 and i have copied and pasted the code below to my
Global.asax file but it desn't trap
the error
I want to trap the 401 access denied
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
try
{
HttpException httpException = (HttpException)exception;
int httpCode = httpException.GetHttpCode();
switch (httpCode)
{
case 401: Response.Redirect("~/Pages/Error/NoAccess.aspx"); break;
case 404: Response.Redirect("~/Pages/Error/PageNotFound.aspx"); break;
default: Response.Redirect("~/Pages/Error/Generic.aspx"); break;
}
}
catch { }
Server.ClearError();
}
I know i can't use the normal custom error in the web config either beacuse
it doesn't work
Any ideas how to trap this?
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="401" redirect="accessdenied.htm" ></customErrors>
HTTP Error 401.1 - Unauthorized: Access is denied due to invalid
credentials.
Internet Information Services (IIS)
Global.asax file but it desn't trap
the error
I want to trap the 401 access denied
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
try
{
HttpException httpException = (HttpException)exception;
int httpCode = httpException.GetHttpCode();
switch (httpCode)
{
case 401: Response.Redirect("~/Pages/Error/NoAccess.aspx"); break;
case 404: Response.Redirect("~/Pages/Error/PageNotFound.aspx"); break;
default: Response.Redirect("~/Pages/Error/Generic.aspx"); break;
}
}
catch { }
Server.ClearError();
}
I know i can't use the normal custom error in the web config either beacuse
it doesn't work
Any ideas how to trap this?
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="401" redirect="accessdenied.htm" ></customErrors>
HTTP Error 401.1 - Unauthorized: Access is denied due to invalid
credentials.
Internet Information Services (IIS)