我環顧四周,建議使用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