获取Windows登录用户名ASP .net

问题描述:

我有一个应用程序部署在具有表单身份验证模式的IIS 8上。 现在有一个需求,如果Windows用户和应用程序用户不同,现在业务需要显示弹出消息并创建审计日志。获取Windows登录用户名ASP .net

为此,我想在应用程序的logincontrol上获取Windows登录用户。我尝试了很多方法,但没有任何帮助。

如果可能或不可以,请引导我。

家伙人。请帮我...

+0

如何http://*.com/问题/ 6615680/asp-net-getting-current-user-name(最后一篇文章)? – reporter 2014-12-19 10:17:51

+0

这可以帮助你[链接](http://*.com/questions/5417125/how-to-get-current-user-whos-accessing-asp-net-app) – LPs 2014-12-19 10:20:25

+0

如果您使用表单身份验证然后应用程序没有Windows用户的知识。理论上可能没有,即使在实践中也是如此。从Web应用程序的角度来看,用户是表单验证用户,没有Windows用户。如果您使用Windows身份验证,那么它是微不足道的。 – 2014-12-19 10:22:21

我用这个网站作为一个参考:

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

(如果本站转载总结下降)

方案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 

场景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 

方案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 

方案4:Windows身份验证在IIS中,模拟对

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 
+0

OP正在使用表单验证,所以这些都不会有帮助。 – 2014-12-19 10:23:18

+0

这些都不能帮助我。我也尝试使用Request.ServerVariables [“LOGON_USER”],但它也返回空字符串,因为在IIS中启用了匿名身份验证。如果我禁用匿名身份验证,则表单身份验证不起作用。 伙计们请帮帮我。 – 2014-12-19 10:37:03

+0

你是否使用MVC?因为您可以指定哪些操作是匿名的,哪些不是基于此操作的。 – user3036342 2014-12-19 11:05:52