HTTP错误401.0 - 未经授权的错误消息

问题描述 投票:6回答:3

我开发了一个简单的ASP.Net MVC 4应用程序,使用Windows身份验证在我们公司的本地网络上运行。它在IIS上部署时工作正常。但是,如果我通过Visual Studio运行应用程序,我会收到错误消息

HTTP Error 401.0 - Unauthorized

这是我的Web.Config文件的样子

<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>

对于调试,应用程序配置为使用“本地IIS Web服务器”运行,并在“应用程序”的“属性” - >“Web”选项卡中选中“使用IIS Express”选项。

c# asp.net asp.net-mvc iis
3个回答
3
投票

事实证明,我必须在我的项目的Windows Authentication属性中启用Anonymous Authentication,禁用Development Server


2
投票

您需要添加到项目Web.config这:

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

其中/ Account / Login是您从控制器登录的方法。


0
投票

确保已启用目录浏览。

请参阅此link以在IIS中添加用户。

© www.soinside.com 2019 - 2024. All rights reserved.