Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Is there a way within web.config or IIS 7 settings that will stop the login prompts and just force the user to the 401 error upon being denied due to URL Authorization rule?

Right now, it successfully restricts access to the page, but doesn't display the "401 - Unauthorized: Access is denied due to invalid credentials" error until after you click cancel on the login prompt.

Using Windows 2008 R2, IIS 7.5, Windows Authentication, Impersonation, and URL Authorization.

Below is a sample of how my web.config file looks like...

XML
<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
        <security> 
            <authorization> 
                <remove users="*" roles="" verbs="" /> 
                <add accessType="Allow" roles="iis7test\BobAndFriends" />             

            </authorization> 
        </security> 
    </system.webServer> 
    <location path="bobsSecret.aspx"> 
        <system.webServer> 
            <security> 
                <authorization> 
                    <remove users="" roles="iis7test\BobAndFriends" verbs="" /> 
                    <add accessType="Allow" users="iis7test\Bob" />                  

                </authorization> 
            </security> 
        </system.webServer> 
    </location> 
</configuration> 
Posted
Updated 10-Aug-23 9:26am
v2

 
Share this answer
 
Solved by using httpErrors in web.config. The site now redirects to the custom error page and does not prompt for windows credentials 3 times.

XML
<system.webServer>
   <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File">
     <remove statusCode="401" />
     <error statusCode="401" path="/AccessDenied.aspx" responseMode="ExecuteURL" />
   </httpErrors>
 </system.webServer>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900