如何在asp.net中使用Windows身份验证来获得用户名? [英] How to get user name using Windows authentication in asp.net?
问题描述
我想使用Windows身份验证来获得用户名
I want to get user name using Windows authentication
其实我实现了登录为不同的用户,当点击这个按钮的Windows安全将出现在那里,我们可以给凭据。
Actually I implemented "Sign in as different user",when click this button Windows security will appear there we can give credentials.
在,如果我给一些其他的凭证它仅取当前用户名的时间。
如何从窗户的安全性,指定凭证的用户名?
In that time if I give some other credential it is taking current user name only. How to get that given credential user name from windows security?
在IIS主机应用程序,然后匿名身份验证已禁用和启用Windows身份验证。
Host application in IIS then anonymous authentication has disabled and windows authentication was enabled.
的web.config:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="true"/>
<authorization>
<allow users="*"/>
<deny users="*"/>
</authorization>
</system.web>
<system.webServer>
<directoryBrowse enabled="true" />
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
的.cs
在这里,我得到了默认的用户名总是
Here I am getting the default User name always
string fullName = Request.ServerVariables["LOGON_USER"];
任何想法?在此先感谢
Any ideas? Thanks in advance
推荐答案
您可以获取用户的<一个href=\"http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity%28v=vs.110%29.aspx\">WindowsIdentity在Windows身份验证对象是:
You can get the user's WindowsIdentity object under Windows Authentication by:
WindowsIdentity identity = HttpContext.Current.Request.LogonUserIdentity;
然后就可以获取像identity.Name用户的信息。
and then you can get the information about the user like identity.Name.
请注意,你需要有HttpContext的这些code。
Please note you need to have HttpContext for these code.
这篇关于如何在asp.net中使用Windows身份验证来获得用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!