IIS Windows身份验证-无法拒绝特定用户

问题描述 投票:0回答:1

最近,我开发了一个非常简单的.net核心API,然后将其部署在IIS上,并希望为某些用户启用Windows身份验证。为了能够实现它,我的web.config看起来像

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
     <authentication mode="Windows" />
    <authorization>
      <allow users="Tow\USER1"/>
      <deny users="*"/>
    </authorization>
    </system.web>
    <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Oculus.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>

  </location>

</configuration>

可以看出,只有User1应该被允许访问,但是每个人都可以访问。我的IIS身份验证如下所示:enter image description here

有人可以帮忙吗?

api asp.net-core iis windows-authentication
1个回答
0
投票

从此thread开始,ASP.NET Core不支持也不使用web.config。发布的web.config仅用于IIS托管,因为IIS要求这样做。

一种解决方法是,您可以尝试将system.webServer放入直接用于IIS的配置中。

<configuration>
  <system.webServer>
    <security>
      <authorization>
          <remove users = "*" roles="" verbs="" />
          <add accessType = "Allow" users="Tow\USER1"/>
      </authorization>
    </security>
  </system.webServer>
</configuration>

但是推荐的方法是最好在asp.net核心中编写自己的自定义授权策略

https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/authentication-and-authorization-in-aspnet-web-api

https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2

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