c# - 如何从 ASP.NET 页面获取当前登录的 Windows 帐户?

标签 c# asp.net vb.net security windows-identity

我有一个使用 ASP.NET 表单例份验证的 ASP.NET 3.5 应用程序。当在页面中编辑数据时,我希望能够获取当前登录到计算机的 Windows 用户名(不是登录到 ASP.NET 应用程序,而是登录到 Windows)。

如果我使用 Context.User.Identity.Name.Tostring(),我会得到登录到 ASP.NET 应用程序的用户名,但我需要 Windows 帐户名。

System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()

此外,它仅在我从 Visual Studio 运行网站时有效,但在部署到 IIS 后它返回 NT AUTHORITY\SYSTEM

最佳答案

您必须在配置中将身份验证模式设置为 Windows,并在授权标记中禁用匿名用户。

关于c# - 如何从 ASP.NET 页面获取当前登录的 Windows 帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16184685/

相关文章:

asp.net - URL 编码的冒号在 400 Bad Request 中解析

c# - WPF:TreeView 或 TreeListView header 水平滚动问题

c# - 什么是最好的 C# 到 VB.net 转换器?

asp.net - 数据网格:计算页脚中列的平均值或总和

c# - Linq 到实体 (EF) : How to get the value of a FK without doing the join

c# - DataContractJsonSerializer 没有看到 DataMemberAttribute

c# - Asp.Net 在 json 中返回自定义对象

asp.net - 如何在 ASP.NET MVC 中渲染 HTML 字符串?

c# - 以编程方式在 WPF ControlTemplate 中创建 Storyboard

c# - 私有(private)访问与公共(public)访问