Skip to content

Instantly share code, notes, and snippets.

@steve-jansen
Created August 14, 2013 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-jansen/6234700 to your computer and use it in GitHub Desktop.
Save steve-jansen/6234700 to your computer and use it in GitHub Desktop.
Preventing IIS Integrated Windows Authentication from prompting authenticated users for a new username/password when permission to a URL is denied.
<Script language="C#" runat="server">
void Application_EndRequest() {
// rewrite HTTP 401s to HTTP 403s if the user is authenticated using
// integrated Windows auth with impersonation, but,
// the user lacks permissions to the requested URL
if (Context.User != null &&
Context.User.Identity != null &&
Context.User.Identity.IsAuthenticated &&
Context.User is System.Security.Principal.WindowsPrincipal &&
Context.Response.StatusCode == 401)
{
Context.Response.Clear();
Context.Response.StatusCode = 403;
}
}
</script>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" roles="Domain Users" />
</authorization>
</security>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment