我们的应用程序AngularJS2 Asp.Net Core API SQL Server中具有以下技术堆栈
现在,我们需要在创建/编辑给定项目(即Core API)的过程中在表中存储登录用户的用户名。
我们已经尝试过
使用Visual Studio时,我使用WindowsIdentity获得用户名,但是使用IIS,它的值为Asp.Netcore,即池名
Windows身份验证已启用,匿名身份验证已禁用
使用IIS版本6.1
我有什么想念的吗?
我环顾四周,建议使用Windows身份验证创建Asp.Net Core WebApi应用程序。
因此,当我使用Windows身份验证创建Asp.Net Core WebApi时,它起作用了,并且在User.Identity对象中获得了值。
所以我创建了2个应用程序,即一个带有Windows身份验证的应用程序,一个没有Windows身份验证的应用程序,然后比较了所有文件并发现以下文件中的更改
forwardWindowsAuthToken
-是的,之前曾尝试过,但问题并未解决,Daboul提出了同样的建议windowsAuthentication
:true和anonymousAuthentication
:false完成此操作后,我就可以在User.Identity对象中进行赋值了。
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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句