Solved redirect to access denied page

Posted on 2006-05-09
Last Modified: 2011-10-03

I am trying to redirect unauthorised users to a custom access denied page but it's not working - unauthorised users are simply redirected back to the login. Here is my web.config

      <customErrors defaultRedirect="ErrorPage.aspx" mode="On">
                  <error statusCode="401.3" redirect="AccessDenied.aspx" />
                  <error statusCode="401" redirect="AccessDenied.aspx" />
                  <error statusCode="500" redirect="servererror.aspx" />
                  <error statusCode="404" redirect="filenotfound.aspx" />
                  <error statusCode="403" redirect="AccessDenied.aspx" />


Any ideas?

thanks, andrea
Question by:andieje
    LVL 42

    Expert Comment

    Are you using forms security?  If so, I believe that the redirect to the login page specified in your web.config file overrides the customErrors handling.  I suspect that the forms level security actually catches the 401 error and handles it so it's never making it to the IIS error handling.
    LVL 33

    Accepted Solution

    frodo is right, but I don't think the 401 is overridden, it's never thrown in the first place.

    You may be able to do this in global.asax

          Protected Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As System.EventArgs)
                If User.Identity.IsAuthenticated = False And Request.Path <> "/login.aspx" Then
                End If
          End Sub

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Removing information on Duplicate XML Nodes 24 58
    Web.Config Connection String 1 36 mvc 2 30
    Azure Web App - See files 3 14
    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now