如何从Asp.Net web获取客户端系统登录用户名 [英] How to get Client System Logged in User Name from Asp.Net web

查看:230
本文介绍了如何从Asp.Net web获取客户端系统登录用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string  SystemUserName = Request.LogonUserIdentity.Name; 





i在我的本地机器上执行此操作它正在检索当前用户名。在服务器中部署之后,它仅返回登录用户名的服务器。

解决方案

尝试下面的一个。



  protected   void  Page_Load( object  sender,EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
Page.Title = + User.Identity.Name;的主页;
}
else
{
Page.Title = 访客用户的主页。;
}
}





欲了解更多信息: HttpContext.User Property



更新



请确保在Web.Config文件中设置Windows身份验证。



Web.Config



< authentication mode =Windows>< / authentication> ; 


string SystemUserName = Request.LogonUserIdentity.Name;



i execute this in my local machine it is retrieving current user name, After deploying in Server, it is returning only Server Logged in Username.

解决方案

Try below one.

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        Page.Title = "Home page for " + User.Identity.Name;
    }
    else
    {
        Page.Title = "Home page for guest user.";
    }
}



For more info: HttpContext.User Property

UPDATE

Please make sure you are setting windows authentication in Web.Config file.

Web.Config

<authentication mode="Windows"></authentication>


这篇关于如何从Asp.Net web获取客户端系统登录用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆