我环顾四周,建议使用Windows身份验证创建Asp.Net Core WebApi应用程序。
所以,当我使用Windows身份验证创建了Asp.Net Core WebApi时,它工作并获取了User.Identity对象中的值。
所以我创建2级的应用,即一个使用Windows身份验证而另一个没有,再对比所有文件,发现变化以下文件
- forwardWidnowsAuthToken - 诚然,这是以前试过,但问题并没有解决,同被Daboul建议
- launchSettings.json,集 “windowsAuthentication”:真& “anonymousAuthentication”:假
这样做后,我能值User.Identi ty对象。
的launchSettings.json文件:
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false
}
}
的Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore forwardWindowsAuthToken="true" processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\YourWebsite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</configuration>
我有同样的问题,但与生产iis 7.5。在我的开发机器上,我得到了我的ntld,但是当我部署到prod时,我仍然得到应用程序池名称。部署时没有launchSettings.json文件。部署到生产时是否有同样的问题? – freddoo
更新 - 我改变我的System.Security.Principal.WindowsIdentity.GetCurrent()。名称为User.Identity.Name现在它的工作。我以前没有工作。 – freddoo