How to fix Access Denied 401.2 in ASP.Net
You may get the following type of error (screen shot below) or you may get
a black and white error page from IIS about 401 Access denied.
Your code ran fine on your computer for testing, but once you upload it to your
ASP.Net web host, you start getting this error
about Access Denied 401.
One possible cause is that the server does not have permissions configured on the folder you
are trying to access, but most web host have the correct permissions set to allow anonymous access, so
before you blame the server, check your web.cofig file to see if you are denying anonymous users from
accessing your site (see offending code below the image).
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings/>
<system.web>
<authorization>
<deny users="?" />
<allow users="*"/>
</authorization>
</system.web>
</configuration>
To Fix 401 Access Denied:
- Remove the red line above from your code completely and test your site again. This does
change the rules of access for your site, so you should refer to MS documentation about ASP.Net
authorization and learn how to properly accomplish your goals of securing
your website..