Handling Custom Errors 401.2

P

Patrick.O.Ige

How can i get to redirect users if the get error 401.2 to another page?
I guess i should be possible to do it in Global.asax?
Or are there any better ways around it..
Any better solutions in ASP.NET 2.0?
Patrick
 
P

Patrick.O.Ige

I'm trying to use this code:-

Private Sub Global_EndRequest(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.EndRequest
If Response.StatusCode = 401 AndAlso Request.IsAuthenticated = True Then
Response.ClearContent()
Server.Execute("http://server/tests.aspx")
End If
End Sub

WHICH I CONVERTED TO C# but it seems not to fire:( don't know what 'm
missing
Thanks
private void Global_EndRequest(object sender, System.EventArgs e)

{

if (Response.StatusCode == 401 && Request.IsAuthenticated == true)

{

Response.ClearContent();

Server.Execute("http://server/tests.aspx");



}

}
 
J

Juan T. Llibre

Hi, Patrick.

See my reply in the "Well global.asax didn't work as well as hoped" thread.

There's sample code there.
 
P

Patrick Olurotimi Ige

Thx Juan i had a brief look and it seems intersting and clean..
Will give that a try,
Thx
Patrick
 
P

Patrick Olurotimi Ige

Thx Juan for the hint but with the code you posted i can't capture the
HTTPEXCEPTION 401 but exception 404 works if i try browsing an ASPX page
that doesn;'t exist

I have included:-

Case 401
errMessage &= "You are not authorised to view this page."

to loop through but it doesn't seem to work.

I have Windows Integrated
Auth and Basic Auth with a selected DOMAIN.

Any clue why it isn't working?
Thanks
 
J

Juan T. Llibre

Hi, Patrick.

IIS defines a number of different 401 errors
that indicate a more specific cause of the error. :

401 - Access denied.
401.1 - Logon failed.
401.2 - Logon failed due to server configuration.
401.3 - Unauthorized due to ACL on resource.
401.4 - Authorization failed by filter.
401.5 - Authorization failed by ISAPI/CGI application.
401.7 - Access denied by URL authorization policy on the Web server.
This last error code is specific to IIS 6.0.

It might be that you have to take *those* into consideration
if you want a *specific* error code captured.

I'd try using 401.1 to test catching a "logon failed" exception

Mind you, it could very well be that Windows Integrated Authentication
preempts any IIS authorization scheme.

Maybe testing if the 401 exception works with Forms Authentication would
help us find out if Windows Authentication does preempt IIS's authentication.
 
P

Patrick Olurotimi Ige

Thanks Juan
Wow i didn't know the status code were this lot...
I was actually thinking of looking through specific ones but i taught
401 will do since i just wnated to look in ACCESS DENIED error..becos i
got it working before but when i came across your solution it was more
cleaner..
I would actually test it for both FORMS AUTH and WINDOWS AUTH and feed
you back.
Patrick
 
P

Patrick Olurotimi Ige

Hi Juan...
I don;t think by adding 401.1 or 401.3 would do the trick
I tried testing with those but no luck..
404 works fine
And i know i get the ACCESS DENIED Error message 401.3 for example
And incase i use IIS version 5
Patrick
 
J

Juan T. Llibre

Thanks for testing this out, Patrick.
Now we know a bit more than before ... ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top