c# - 获取 Windows 登录用户名 ASP .net

标签 c# asp.net iis-8

我在 IIS 8 上部署了一个具有表单例份验证模式的应用程序。 现在有一个要求,如果 Windows 用户和应用程序用户不同,企业希望显示弹出消息并创建审计日志。

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

请指导我是否可能。

伙计们任何人..请帮助我......

最佳答案

我使用这个网站作为引用:

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:IIS 中的 Windows 身份验证,模拟

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

关于c# - 获取 Windows 登录用户名 ASP .net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27563703/

相关文章:

C# 如何使用参数读取控制台输出

asp.net - 在没有 System.Web 的 ASP.NET 中获取 Windows 用户名

iis - 从Visual Studio 2012到远程IIS 8服务器的Web部署

asp.net - 错误 : "The configuration section ' system. webServer/management/delegation' 无法读取,因为它缺少架构

asp.net-mvc - IIS 8 Express 不提供页面

asp.net-core - 将 .Net Core 作为 DLL 部署到 IIS - 无法使用命令行 '"dotnet"site.dll' 启动进程

c# - 未分配变量的值是多少(null VS 0)

c# - 值等于数组中的任何值?

c# - 如果没有等待完成,BackgroundService 永远不会启动/停止

javascript - 如何知道图像是否无法在 javascript 中加载?