簡體   English   中英

如何獲取用戶登錄我的應用程序的計算機帳戶?

[英]How to get machine account from which the user login to my application?

如何在Form authentication的情況下獲取用戶訪問應用程序的用戶計算機帳戶。

我使用以下方法,但它沒有獲得所需的數據:

protected string[] TrackUser()
{
    System.Web.HttpContext context = System.Web.HttpContext.Current;
    string IP = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    string compName = (Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
    string account = Request.ServerVariables["AUTH_USER"];
    string[] user_network_data = new string[3];
    if (!string.IsNullOrEmpty(IP))
    {
        string[] addresses = IP.Split(',');
        if (addresses.Length != 0)
        {
            IP = addresses[0];
        }
    }
    else
    {
        IP = context.Request.ServerVariables["REMOTE_ADDR"];
    }
    user_network_data[0] = IP;
    user_network_data[1] = compName;
    user_network_data[2] = account;
    return user_network_data;
}

我想你只是從請求中抓取錯誤的初始信息。 試試這些:

string IP = context.Request.UserHostAddress;
string compName = context.Request.UserHostName;
string account = context.Request.LogonUserIdentity.Name;

我認為一旦你有正確的數據開始,你的其余代碼應該可以正常工作。

暫無
暫無

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

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