Handling Custom Errors 401.2

Discussion in 'ASP .Net' started by Patrick.O.Ige, Jul 26, 2005.

  1. 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
     
    Patrick.O.Ige, Jul 26, 2005
    #1
    1. Advertising

  2. 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");



    }

    }

    "Patrick.O.Ige" <> wrote in message
    news:...
    > 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
    >
    >
     
    Patrick.O.Ige, Jul 26, 2005
    #2
    1. Advertising

  3. Fixed it!
    forgot it was C#
    I for got to add the Handler


    "Patrick.O.Ige" <> wrote in message
    news:...
    > 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");
    >
    >
    >
    > }
    >
    > }
    >
    > "Patrick.O.Ige" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Patrick.O.Ige, Jul 26, 2005
    #3
  4. Hi, Patrick.

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

    There's sample code there.



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Patrick.O.Ige" <> wrote in message
    news:...
    > 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");
    >
    >
    >
    > }
    >
    > }
    >
    > "Patrick.O.Ige" <> wrote in message
    > news:...
    >> 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
    >>
    >>

    >
    >
     
    Juan T. Llibre, Jul 26, 2005
    #4
  5. Thx Juan i had a brief look and it seems intersting and clean..
    Will give that a try,
    Thx
    Patrick

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Jul 26, 2005
    #5
  6. 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


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Aug 17, 2005
    #6
  7. 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.





    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    > 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
     
    Juan T. Llibre, Aug 17, 2005
    #7
  8. 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


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Aug 17, 2005
    #8
  9. 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



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Aug 18, 2005
    #9
  10. Thanks for testing this out, Patrick.
    Now we know a bit more than before ... ;-)




    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Patrick Olurotimi Ige" <> wrote in message
    news:%...
    > 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
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    Juan T. Llibre, Aug 18, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    955
    Mark Goldin
    Jan 17, 2004
  2. =?Utf-8?B?RGF2ZQ==?=

    WebRequests & 401 Unauthorized errors

    =?Utf-8?B?RGF2ZQ==?=, May 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    407
    =?Utf-8?B?RGF2ZQ==?=
    May 5, 2004
  3. Simon
    Replies:
    4
    Views:
    924
    Anonymous Poster
    Oct 25, 2004
  4. Steve Richter
    Replies:
    2
    Views:
    10,516
    Shane Thomas
    Apr 30, 2005
  5. gilly3
    Replies:
    0
    Views:
    702
    gilly3
    Mar 20, 2006
Loading...

Share This Page