[英]in an IIS web app, how do I get the windows user name? - not the process username
I have inherited an old asp.net web app. 我继承了一个旧的asp.net网络应用程序。 Part of the login process is intended to collect the windows username (not the process username).
登录过程的一部分旨在收集Windows用户名(而不是过程用户名)。 This used to work (years ago) but a new compile of the system returns the App Pool name / username instead of the windows username.
这曾经工作(几年前),但是系统的新编译返回了“应用程序池”名称/用户名,而不是Windows用户名。
The username is collected before authentication by the website, originally using HttpContext.Current.User.Identity.Name I have tried all the other options that have been suggested with no change in the results. 用户名是在网站进行身份验证之前收集的,最初是使用HttpContext.Current.User.Identity.Name,我尝试了所有建议的其他选项,但结果没有变化。
string loginName;
loginName = Environment.UserName;
loginName = System.Windows.Forms.SystemInformation.UserName;
loginName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
loginName = HttpContext.Current.User.Identity.Name;
loginName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
loginName = System.Windows.Forms.SystemInformation.UserName;
loginName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.SamAccountName;
loginName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName;
I tried these one at a time (not all together) and in the target environment only ever got the App Pool name or App Pool username. 我一次尝试了一次(并非全部尝试一次),并且在目标环境中只获得了应用程序池名称或应用程序池用户名。 I have tried every combination of Authentication in IIS, the only one that makes a difference is ASP.NET impersonation which changes from App Pool name to impersonation user name.
我已经尝试了IIS中身份验证的每种组合,唯一起作用的是ASP.NET模拟,它从应用程序池名称更改为模拟用户名。
On my local PC, launched out of Visual Studio, they all work to return the windows logged in username. 在从Visual Studio启动的本地PC上,它们都可以返回登录的Windows用户名。
I'm quite new to asp.net web apps, and I don't know what else to try. 我对asp.net网络应用程序还很陌生,而且我不知道还能尝试什么。
You have stumbled on the answer. 您偶然发现了答案。 If you want the server to automatically know the windows user, that windows user's credentials need to be passed to the application.
如果希望服务器自动认识Windows用户,则需要将该Windows用户的凭据传递给应用程序。 If you use the Kerberos or NTML authentication options (Windows Authentication) that set of credentials is passed automatically.
如果使用Kerberos或NTML身份验证选项(Windows身份验证),则会自动传递一组凭据。 Otherwise you need to prompt the user to enter credentials.
否则,您需要提示用户输入凭据。 You don't have to use impersonation, but you can programmatically impersonate the logged in user if your app pool user has sufficient access to the dc catalog.
您不必使用模拟,但是如果您的应用程序池用户具有对dc目录的足够访问权限,则可以以编程方式模拟已登录的用户。 More on that here: https://docs.microsoft.com/en-us/previous-versions/msp-np/ff647405(v=pandp.10)#impersonating-the-original-caller-programmatically
有关更多信息,请访问: https : //docs.microsoft.com/zh-cn/previous-versions/msp-np/ff647405(v=pandp.10)#impersonating-the-original-caller-programmatically
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.