问题描述
我们的应用程序中有以下技术堆栈
AngularJS2
Asp.Net核心API
SQL Server
现在我们需要在给定项目的创建/编辑期间,在Core API中存储用户登录用户的用户名。
我们尝试过
'UL>
我在使用Visual Studio时使用WindowsIdentity获取用户名,但是使用IIS时,它提供的值为Asp.Netcore即池名
启用Windows身份验证并禁用匿名身份验证
使用IIS版本6.1
我错过了什么吗?
我环顾四周,建议创建Asp.Net Core WebApi使用Windows身份验证的应用程序。
因此当我使用Win创建Asp.Net Core WebApi时dows认证它有效,我在User.Identity对象中获得了值。
所以我创建了2个应用程序,即一个使用Windows身份验证,一个没有,然后比较所有文件并找到以下文件中的更改
- forwardWidnowsAuthToken - 是的,这是之前尝试但是问题没有解决,Daboul提出同样的建议
- launchSettings.json,设置windowsAuthentication:true& anonymousAuthentication:false
执行此操作后,我能够在User.Identity对象中赋值。
launchSettings.json文件:
{
的iisSettings:{
的windowsAuthentication:真的,
的anonymousAuthentication:假
}
}
Web.Config:
<?xml version =1.0encoding =utf-8?>
< configuration>
< system.webServer>
< handlers>
< add name =aspNetCorepath =*verb =*modules =AspNetCoreModuleresourceType =Unspecified/>
< / handlers>
将aspNetCore forwardWindowsAuthToken = 真 processPath = C:\Program Files\dotnet\dotnet.exe \YourWebsite.dll 参数= stdoutLogEnabled = 真 stdoutLogFile = \\。 \\ logs\stdout/>
< security>
< authentication>
< windowsAuthentication enabled =true/>
< anonymousAuthentication enabled =false/>
< / authentication>
< / security>
< /system.webServer>
< / configuration>
We have following technical stack in our applicationAngularJS2Asp.Net Core APISQL Server
Now we need to store User Name for the Logged in User in table during Create/Edit for given item i.e. in Core API.
We have tried with
- WindowsIdentity.GetCurrent().Name, it gives IIS APPPOOL\Asp.netCore
- HttpContext.User.Identity gives null value
I get User Name with WindowsIdentity while working with Visual Studio, but with IIS, it gives value as Asp.Netcore i.e. pool name
Windows Authentication is enabled and Anonymous Authentication is disabled
Using IIS Version 6.1
Am I missing anything?
I looked around and it was suggested to create Asp.Net Core WebApi application using Windows Authentication.
So when i created Asp.Net Core WebApi using Windows Authentication it worked and i got values in User.Identity objects.
So i created 2 applications i.e. one with Windows Authentication and one without, and then compared all files and found changes in following files
- forwardWidnowsAuthToken - True, this was tried before but issue was not solved and same was suggested by Daboul
- launchSettings.json, Set "windowsAuthentication": true & "anonymousAuthentication": false
After doing this, I was able to values in User.Identity object.
The launchSettings.json file:
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false
}
}
The 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>
这篇关于Asp.net核心Web API - 当前用户& Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!