簡體   English   中英

ASP Net獲取用戶名

[英]Asp Net get username

我對此進行了Google搜索,但沒有一種解決方案可以解決這種情況。

我的web.config:

<configuration>
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true">
            </compilation>
      <authentication mode="Windows" />

    </system.web>
</configuration>

我的aspx頁面:

<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
        Response.Write("Name:" + opl);
    }
</script>

我有一個空字符串,有什么想法嗎?我嘗試了Request.ServerVariables但也為用戶提供了一個空字符串。

如果要獲取登錄用戶的名稱,可以使用

var user = User.Identity.Name

要么

var user = User.Identity.UserName

嘗試以下方法:

var username = User.Identity.Name

您要做的是查詢HttpContext:

http://msdn.microsoft.com/zh-CN/library/system.web.httpcontext.user.aspx

它將包含有關當前登錄用戶的所有信息。

暫無
暫無

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

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