【发布时间】:2014-10-14 12:12:30
【问题描述】:
是否可以在不使用 activex 对象的情况下在远程服务器中托管的 asp.net 中获取客户端的 windows 用户名?
我使用了以下代码
Response.Write("HttpContext.Current.Request.LogonUserIdentity.Name " & HttpContext.Current.Request.LogonUserIdentity.Name)
Response.Write("<br/>")
Response.Write("HttpContext.Current.Request.IsAuthenticated " & HttpContext.Current.Request.IsAuthenticated)
Response.Write("<br/>")
Response.Write("HttpContext.Current.User.Identity.Name " & HttpContext.Current.User.Identity.Name)
Response.Write("<br/>")
Response.Write("System.Environment.UserName " & System.Environment.UserName)
Response.Write("<br/>")
Response.Write("Security.Principal.WindowsIdentity.GetCurrent().Name() " & System.Security.Principal.WindowsIdentity.GetCurrent().Name())
Response.Write("<br/>")
但它总是给我服务器用户名而不是客户端用户名。
【问题讨论】:
-
您的虚拟目录/应用程序是如何配置的?
-
只有在使用 Windows 身份验证时才有可能。
-
这是可能的,但您访问此信息的方式在每个浏览器中都不同(如果它甚至存在的话)。例如 Mozilla FireFox 你使用nsIEnvironment。因此,您的 javascript 将首先检测浏览器,然后相应地访问 windows 用户名。此外,如果您使用 C#,您可以使用 WAFFLE Source
-
@AdrianoRepetti 使用 Windows 身份验证仅适用于 Intranet,但不适用于 Internet 不是吗?
-
是的,仅在 Intranet 中,因为无法从不受信任的站点使用 JavaScript 访问该信息可能是一个安全问题。
标签: javascript asp.net windows iis activexobject