api - IIS Windows 身份验证 - 无法拒绝特定用户
问题描述
最近我开发了一个非常简单的 .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 身份验证如下所示:
有人可以帮忙吗?
解决方案
从这个线程,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 core 中编写你自己的自定义授权策略
https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2
推荐阅读
- google-chrome - 使用 Google chrome 扩展重定向 url
- c# - Stripe Simple Checkout 与取消按钮的集成
- github - Revert everything you did in github
- bash - 获取目录 bash 中的扩展
- python - 使用 wrap 在 numpy 中获取索引的最佳方法
- r - 使用 spotifyr 从 Spotify Top Charts 获取数据
- html - 网格模板区域问题
- python - Segmentation Fault shell 代码测试 kali 2018
- mysql - 在 sequelize 中关联两个表
- eclipse - Eclipse“指定了未知版本的 Tomcat”(Ubuntu)