如何从 ASP.NET 页面获取当前登录的 Windows 帐户? [英] How do I get the currently loggedin Windows account from an ASP.NET page?
问题描述
我有一个使用 ASP.NET 表单身份验证的 ASP.NET 3.5 应用程序.当在页面中编辑数据时,我希望能够获取当前登录到计算机的 Windows 用户名(未登录到 ASP.NET 应用程序,而是登录到 Windows).
I have an ASP.NET 3.5 application that uses ASP.NET forms authentication. I want to be able to get the Windows user name currently logged into the computer (NOT logged into the ASP.NET application, but into Windows) when data is edited in a page.
如果我使用 Context.User.Identity.Name.Tostring()
,我会得到登录到 ASP.NET 应用程序的用户名,但我需要 Windows 帐户名.
If I use Context.User.Identity.Name.Tostring()
, I get the user name logged into the ASP.NET application, but I need the Windows account name.
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()
此外,它仅在我从 Visual Studio 运行网站时才有效,但在部署到 IIS 后它返回 NT AUTHORITYSYSTEM.
Also, it only works when I run the website from Visual Studio, but after deploying to IIS it returns NT AUTHORITYSYSTEM.
推荐答案
您必须在配置中将身份验证模式设置为 Windows
还禁用授权标签中的匿名用户.
You have to set authentication mode to Windows
in your configuration & also disable anonymous users in authorization tag.
这篇关于如何从 ASP.NET 页面获取当前登录的 Windows 帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!