简体   繁体   English

获取Windows登录用户名ASP .net

[英]Get Windows logged-in Username ASP .net

I have an application deployed on IIS 8 having forms authentication mode. 我在IIS 8上部署了一个具有表单身份验证模式的应用程序。 Now there is a requirement where business wants to show a popup message and create an audit log if the Windows User and the Application user is different. 现在有一个要求,即如果Windows用户和应用程序用户不同,企业希望显示弹出消息并创建审核日志。

For this I want to get the Windows Logged in user on logincontrol of the applicaiton. 为此,我想在应用程序的logincontrol上获取Windows登录用户。 I have tried many ways but nothing is helping. 我尝试了很多方法但没有任何帮助。

Please guide me if it is possible or not. 如果可能,请指导我。

Guys anyone.. Please help me... 伙计们..请帮帮我......

I use this site as a reference: 我使用这个网站作为参考:

http://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net/ http://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net/

(reposted summary in case site goes down) (转发摘要以防案例网站出现故障)

Scenario 1: Anonymous Authentication in IIS with impersonation off. 方案1:IIS中的匿名身份验证,模拟关闭。

HttpContext.Current.Request.LogonUserIdentity.Name  COMPUTER1\IUSR_COMPUTER1
HttpContext.Current.Request.IsAuthenticated False
HttpContext.Current.User.Identity.Name  -
System.Environment.UserName ASPNET
Security.Principal.WindowsIdentity.GetCurrent().Name    COMPUTER1\ASPNET

Scenario 2: Windows Authentication in IIS, impersonation off. 方案2:IIS中的Windows身份验证,模拟关闭。

HttpContext.Current.Request.LogonUserIdentity.Name  MYDOMAIN\USER1
HttpContext.Current.Request.IsAuthenticated True
HttpContext.Current.User.Identity.Name  MYDOMAIN\USER1
System.Environment.UserName ASPNET
Security.Principal.WindowsIdentity.GetCurrent().Name    COMPUTER1\ASPNET

Scenario 3: Anonymous Authentication in IIS, impersonation on 方案3:IIS中的匿名身份验证,模拟

HttpContext.Current.Request.LogonUserIdentity.Name  COMPUTER1\IUSR_COMPUTER1
HttpContext.Current.Request.IsAuthenticated False
HttpContext.Current.User.Identity.Name  -
System.Environment.UserName IUSR_COMPUTER1
Security.Principal.WindowsIdentity.GetCurrent().Name    COMPUTER1\IUSR_COMPUTER1

Scenario 4: Windows Authentication in IIS, impersonation on 方案4:IIS中的Windows身份验证,模拟

HttpContext.Current.Request.LogonUserIdentity.Name  MYDOMAIN\USER1
HttpContext.Current.Request.IsAuthenticated True
HttpContext.Current.User.Identity.Name  MYDOMAIN\USER1
System.Environment.UserName USER1
Security.Principal.WindowsIdentity.GetCurrent().Name    MYDOMAIN\USER1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM