如何从 ASP.NET 页面获取当前登录的 Windows 帐户? [英] How do I get the currently loggedin Windows account from an ASP.NET page?

查看:24
本文介绍了如何从 ASP.NET 页面获取当前登录的 Windows 帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆