ASP.NET Custom Error Page - What Am I missing??

I have a web site with restricted access.
Currently the users see
Server Error in '/' Application (in red)
---------------------------------------------
Access Denied.  bla bla bla... .
if they are denied access.

I'm trying to implement a custom page (which will explain why they were denied access, who to contact if they need access and then a link to return them to the original page.)

I've read several of the posts in the knowlegebase and most of them center around the same things.

The IIS Configuration, The Global.aspx and the web.config file

I have configured the custom error in IIS as shown below.

There is nothing in the Sub Application_Error portion of the Global.asax file

Since the the site also contains a sub folder that further restricts access (it contains the Admin pages for the site) so there are two web.config files.

I'm using windows groups and the authorization section to limit access to whole site and the Admin folder so the root folder contains a web.config file with these entries
<authorization>
      <allow roles="domain\rc-expertise-user-ro"/>
      <deny users="?"/>
</authorization>

and the second web.config in the Admin folder limits access futher with these.  
 <authorization>
       <allow roles="domain\rc-expertise-admin"/>
        <deny users="*" />
 </authorization>

Still when I attempt to access a page in the Admin I get the ugly

Server Error in '/' Application

Access Denied.  rather than my page.

What have I missed?


CustomErrors.JPG
11ptManAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

11ptManAuthor Commented:
Yes,

The following is in both web.config files

    <customErrors mode= "On" >
        <error statusCode ="401" redirect ="~/NotAdmin.htm"/>
        <error statusCode="403" redirect="~/NoAccess.htm" />
        <error statusCode="404" redirect="~/FileNotFound.htm" />
      </customErrors>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tanujchandnaCommented:
Hi,

Assign Network services Read, Write and Modify permission to website and check it works for you or not.
0
11ptManAuthor Commented:
Neither of these really resolved the issue but they did lead me to
http://www.codeproject.com/kb/aspnet/Custon401Page.aspx

where I learned the issue is specific to the 401 error and how to resolve it.  

Here is the gist of the solution
Resolution
That was also the result of my research. The whole thing works like this:

The browser sends request without credentials to the server.
Server rejects this request and answers with "401 Access Denied".
Browser recognizes 401 and if it has appropriate credentials does not show this message. The second request with credentials will be posted. The requested page will be sent to the browser.
If the browser has no credentials the second post will not take place. The received "401 Access Denied" will be shown.
The workaround is to manipulate the content of "401 Access Denied" response. The browser uses the header of this response to determine 401 case. It means we can manipulate the HTML content without influencing the whole challenge. For instance we can add the following code in the Application_EndRequest event of Global.asax.cs.

 Collapse Copy Code  protected void Application_EndRequest(Object sender,
                                             EventArgs e)
  {
     HttpContext context = HttpContext.Current;
     if (context.Response.Status.Substring(0,3).Equals("401"))
     {
        context.Response.ClearContent();
        context.Response.Write("<script language="javascript">" +
                     "self.location='../login.aspx';</script>");
     }
  }Now, the whole thing works like this:

The browser sends request without credentials to the server.
Server rejects this request and answers with "401 Access Denied" Header + our JavaScript.
Browser recognizes 401 and if it has appropriate credentials does not show this message. Our HTML will not be rendered and JavaScript will not be executed. The second request with credentials will be posted. The requested page will be sent to the browser.
If the browser has no credentials, the second post will not take place. The received "401 Access Denied" will be shown. Our HTML will be rendered and JavaScript will be executed. The client side redirection will take place. The browser will show a custom 401 page.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.