ASP.NET Web.config身份验证/授权设置

时间:2016-05-04 13:53:19

标签: asp.net-mvc authentication web-config authorization windows-authentication

我尝试在Web.config文件中配置我的MVC5项目的IIS身份验证设置。

这就是我所拥有的。我希望启用Windows身份验证并禁用匿名身份验证。

enter image description here

但是在IIS中发布我的包后,设置就是这样。

enter image description here

在Web.config中还要将匿名身份验证设置为已禁用,我还需要做什么? 那不是<deny users "?"/>应该做的吗?

2 个答案:

答案 0 :(得分:4)

我们一步一步走:

  1. 打开Internet信息服务(IIS)管理器:

    • 如果您使用的是Windows Server 2012或Windows Server 2012 R2:
    • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“确定” Internet信息服务(IIS)管理器。
    • 如果您使用的是Windows 8或Windows 8.1:
    • 按住Windows键,按字母X,然后单击“控制” 面板。单击“管理工具”,然后双击“Internet” 信息服务(IIS)管理器。
    • 如果您使用的是Windows Server 2008或Windows Server 2008 R2:
    • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“管理工具” 点击

      Internet信息服务(IIS)管理器。

    • 如果您使用的是Windows Vista或Windows 7:

    • 在任务栏上,单击“开始”,然后单击“控制面板”。
    • 双击“管理工具”,然后双击“Internet” 信息服务(IIS)管理器。

      1. 在“连接”窗格中,展开服务器名称,展开“站点”,然后转到要配置的层次结构窗格中的级别,然后单击“网站”或“Web应用程序”。
      2. 滚动到“主页”窗格中的“安全”部分,然后双击“身份验证”。 4.在Authentication窗格中,选择Anonymous Authentication,然后在Actions窗格中单击Disable。
  2. 或者您可以通过配置文件禁用:

    <location path="Contoso">
       <system.webServer>
          <security>
             <authentication>
                <anonymousAuthentication enabled="false" />   <!--This line you need-->
                <basicAuthentication enabled="true" defaultLogonDomain="Contoso" />
                <windowsAuthentication enabled="true" />
              </authentication>
          </security>
       </system.webServer>
    </location>
    

    拒绝匿名用户访问整个网站:

       <authorization>
        <deny users="?" ></deny>    
        </authorization>
    

    希望它有所帮助;)

答案 1 :(得分:-2)

右键单击匿名身份验证,然后单击禁用

相关问题