Redirecting on 401.2 unauthorized

Topics: General Topic, WCF Cache Service
Jun 10, 2012 at 12:49 PM

If a user is set to deny within a role or if the user is not added to any roles the following message appears when trying to access the site: Error message 401.2.: Unauthorized: Logon failed due to server configuration.

That is of course correct.

My question is how to redirect the user to an Unauthorized.aspx page instead of showing the default error message?

Coordinator
Jun 10, 2012 at 1:23 PM

Try to see here:

http://www.codeguru.com/csharp/.net/net_debugging/article.php/c19411/Web-Application-Error-Handling-in-ASPNET.htm

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Jun 10, 2012 at 2:07 PM
Edited Jun 10, 2012 at 2:08 PM

Thanks Andrea.

I have already tried the following:

 

<customErrors defaultRedirect="Error.aspx" mode="On">
      <error statusCode="401" redirect="Unauthorized.aspx" />
    </customErrors>
But thats doesn't seem to trigger the redirect on Error message 401.2.: Unauthorized Any idea why that might be?
Coordinator
Jun 10, 2012 at 2:15 PM

Try this workaround:

http://www.moollan.net/blog/2005/04/08/redirected-url-for-a-4012-unauthorized-access-in-aspnet-using-globalasax/

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Jun 10, 2012 at 2:34 PM
Edited Jun 10, 2012 at 2:54 PM
void Application_EndRequest(object sender, EventArgs e)
        {
            if (Response.StatusCode == 401)
                Response.Redirect("Unauthorized.aspx");
        }

Got it working by addidng this to the global.asax

Thanks.

Coordinator
Jun 11, 2012 at 6:14 AM

Hi,

the code you have seen in the article is VB.NET J

This is the c# version of the method (global.asax):

void Application_EndRequest(object sender, System.EventArgs e) {
if (((Response.StatusCode == 401)
&& (Request.IsAuthenticated
== true))) {
Response.ClearContent()
;
string
url = AppSettings("", url, "");
Response.Redirect(url);
}
}

Regards,

Andrea.

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com