Link to home
Start Free TrialLog in
Avatar of Codeaddict7423
Codeaddict7423Flag for United States of America

asked on

redirect loop and intermittent HTTP 404 error in C#

Hello,
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"/>
    </customErrors>


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"))
            {
                context.Response.ClearContent();
                Response.Redirect("./ErrorPage/UnauthorizedAccess.aspx");
            }

            if (context.Response.Status.Contains("400"))
            {
                context.Response.ClearContent();
                Response.Redirect("./ErrorPage/UnauthorizedAccess.aspx");
            }

        }

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.
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial