簡體   English   中英

在不使用ActiveX對象的情況下獲取Windows用戶名

[英]Get windows username without using activex object

是否可以在不使用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/>")

但是它總是給我服務器用戶名而不是客戶端用戶名。

您可以嘗試使用ServerVariables

string Hostname=Request.ServerVariables["REMOTE_HOST"];
string Username=Request.ServerVariables["REMOTE_USER"];

如果您使用的是“ Windows身份驗證”,則此行將起作用

Response.Write("HttpContext.Current.User.Identity.Name " & HttpContext.Current.User.Identity.Name)

參考: MSDN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM