redirect loop and intermittent HTTP 404 error in C#

I have an application that seeks to authenticate users  by their windows login.
The purpose of this filter is to allow certain users access to certain pages and others to an "Access Denied" page.

In my web.config page, I have the following:

    <customErrors mode="Off" defaultRedirect="UnauthorizedAccess.aspx" redirectMode="ResponseRedirect">
      <error statusCode="400" redirect="ErrorPage/UnauthorizedAccess.aspx"/>
      <error statusCode="401" redirect="ErrorPage/UnauthorizedAccess.aspx"/>
      <error statusCode="403" redirect="ErrorPage/UnauthorizedAccess.aspx"/>
      <error statusCode="404" redirect="ErrorPage/UnauthorizedAccess.aspx"/>

In my Global.asax page, I have the following:
protected void Application_EndRequest(Object sender, EventArgs e)
            HttpContext context = HttpContext.Current;
            if (context.Response.Status.Contains("401"))

            if (context.Response.Status.Contains("400"))


The issues are:

Local machine: IE Explorer displays pages as expected,  however, when I upload the application to the server, I get intermittent "The page cannot be displayed" error  messages

Local machine: Google Chrome displays pages as expected, however,  when I upload the application to the server, I a flash message indicating "the page has a redirect loop" followed by a "Bad Request" message

ANY help would be greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Dan McFaddenSystems EngineerCommented:
Can you directly go to the URL?  If not, the I would make sure that authentication is turned off for the "ErrorPage/UnauthorizedAccess.aspx" page.

If the above page is not publically accessible, you will wind up in an authentication required loop.

Dan McFaddenSystems EngineerCommented:
You will need your web.config to contain a section like so:

   <location path="<URL to your error page directory>">
            <allow users="?"/>

Open in new window

Where this "<URL to your error page directory>" should probably be this:  "/errorpages"


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
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

From novice to tech pro — start learning today.