Re: How to catch error 401 access denied and redirect to custom error page ?
- From: Alexey Smirnov <alexey.smirnov@xxxxxxxxx>
- Date: Mon, 4 Aug 2008 12:27:14 -0700 (PDT)
On Aug 4, 2:45 pm, "Patrick.O.Ige" <naijaco...@xxxxxxxxxxx> wrote:
Thanks Alexey.
But in asp.net 2.0 there is no Application_EndRequest event in the global
asax
and by the way i have to disable Allow ananonymous access..
Any ideas
"Alexey Smirnov" <alexey.smir...@xxxxxxxxx> wrote in message
news:78aebe3f-a02e-4eaf-9343-9a0d842838e2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Aug 4, 3:53 am, "rote" <naijaco...@xxxxxxxxxxx> wrote:
I'm using ASP.NET 2.0 and i have copied and pasted the code belowe global
.as 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)
Look at the following tiphttp://www.codeproject.com/KB/aspnet/Custon401Page.aspx- Hide quoted text -
- Show quoted text -
Hi Patrick
you just need to add the code to you global.asax. It simply does not
add all methods by default... Moreover, if you may access the IIS, you
might try to use custom 401. Using the IIS Manager, go to the
properties of your site, then go to the Custom Errors tab to Edit the
various 401 errors and assign a custom redirection.
Hope this helps
.
- References:
- Prev by Date: How do I open a MPP (microsoft project plan) file in asp.net?
- Next by Date: Re: How do I open a MPP (microsoft project plan) file in asp.net?
- Previous by thread: Re: How to catch error 401 access denied and redirect to custom error page ?
- Next by thread: Re: How to catch error 401 access denied and redirect to custom error page ?
- Index(es):
Relevant Pages
|
Loading