简体   繁体   English

在IIS Web应用程序中,如何获取Windows用户名? -不是进程用户名

[英]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.

相关问题 "如何获取用户名@域格式的当前 Windows 用户名?" - How do I get the current windows user's name in username@domain format? 如何在IIS 10上使用C#Razor获取Windows用户域/用户名? - How do you get Windows user domain/username with C# Razor on IIS 10? 如何获取当前Windows登录用户的用户名? - How do I get the current Windows logged-in user's username? 通过带有 Windows 身份验证的 IIS 托管 mvc 应用程序,但我得到 IIS APPPOOL\\ APP 我需要连接的 Windows 用户(与 IIS express 一起使用) - Hosting a mvc app via IIS with windows authentication, but I get IIS APPPOOL\ APP I need the windows user that connects (works with IIS express) 您如何获取进程所有者的用户名? - How do you get the UserName of the owner of a process? 如何获得已登录Windows用户的名字和姓氏? - How do I get the first name and last name of the logged in Windows user? 如何从IIS中的Windows身份验证获取用户名输入? - How to get username input from Windows Authentication in IIS? 在Web App中获取用户名 - Get UserName in Web App 如何在Windows窗体应用程序中获取VPN用户的当前用户身份? - How do I get the Current User identity for a VPN user in a Windows forms app? 如何在C#Web APP中获取当前的Windows登录名? - How to get current Windows Login Name in C# Web APP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM