Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Error 401.0 - Unauthorized error message

I have developed a simple ASP.Net MVC 4 application using Windows Authentication to run on our company's local network. It works fine when deployed on IIS. But if I run the application through Visual studio, I get error message

HTTP Error 401.0 - Unauthorized

Here is how my Web.Config file looks like

<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="WindowsProvider" enabled="true" cacheRolesInCookie="false">
  <providers>
    <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
  </providers>
</roleManager>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxUrlLength="32767" maxQueryStringLength="32767" targetFramework="4.5" />
</system.web>

 <system.webServer>
<modules>
  <!--<remove name="FormsAuthenticationModule" />-->
</modules>
<security>
  <requestFiltering>
    <requestLimits maxUrl="32767" maxQueryString="32767" />
  </requestFiltering>
</security>

For debugging, Application is configured to run using "Local IIS Web Server" with "Use IIS Express" option checked in Applications's Properties ->Web tab.

like image 967
WAQ Avatar asked Jan 29 '17 06:01

WAQ


3 Answers

It turns out to be that I had to Enable Windows Authentication, Disable Anonymous Authentication in the Development Server Properties of my Project.

like image 60
WAQ Avatar answered Nov 15 '22 04:11

WAQ


You need to add to project Web.config this:

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="1" />
    </authentication>
  </system.web>

Where /Account/Login is your login method from controller.

like image 34
Schroet Avatar answered Nov 15 '22 04:11

Schroet


Make sure your Directory Browsing is enabled.

See this link for adding user in IIS.

like image 31
Vijunav Vastivch Avatar answered Nov 15 '22 06:11

Vijunav Vastivch