Re: How to catch error 401 access denied and redirect to custom error page ?



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
.



Relevant Pages

  • Re: Supressing Public ASP Error Codes
    ... Please read the IIS documentation on custom error pages, ... specific internal server error caused by an ASP related error. ... IIS will send this error page to the client, rather than the existing page + ... following error message that was displayed at the bottom of the ...
    (microsoft.public.inetserver.iis.security)
  • Re: Upload a File to a Web Server and error handling
    ... You should be able to trap the error in the Application_Error event handler ... Take a look at the following article for how to create custom ... Brian ... Microsoft Developer Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Thnslicer does not work on Windows 2003
    ... I have adjusted the error to be custom and here is the exact message I get: ... Open IIS Help, which is accessible in IIS Manager, and search for topics titled Web Site Administration, and About Custom Error Messages. ... In the IIS Software Development Kit or at the MSDN Online Library, search for topics titled Debugging ASP Scripts, Debugging Components, and Debugging ISAPI Extensions and Filters. ...
    (microsoft.public.sqlserver.olap)
  • Re: Supressing Public ASP Error Codes
    ... Create your own custom 500-100.asp error page. ... Customise your website in IIS, so that the 500-100 error page points to your ... I am not a literate ASP programmer and the ...
    (microsoft.public.inetserver.iis.security)
  • RE: shorten the page address
    ... And that method take advantage of the IIS 404 error page. ... configure the IIS to use a custom 404 error page. ... So for the following redirect case: ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.inetserver.asp.general)

Loading