[英]Asp Net get username
I Googled about this, but none of solutions solved this situation. 我对此进行了Google搜索,但没有一种解决方案可以解决这种情况。
My web.config: 我的web.config:
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true">
</compilation>
<authentication mode="Windows" />
</system.web>
</configuration>
My aspx page: 我的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>
I'm getting an empty string, any ideas?I tried Request.ServerVariables
but get an empty string for user also. 我有一个空字符串,有什么想法吗?我尝试了
Request.ServerVariables
但也为用户提供了一个空字符串。
If you want to get the name of the logged user you can use 如果要获取登录用户的名称,可以使用
var user = User.Identity.Name var user = User.Identity.Name
or 要么
var user = User.Identity.UserName var user = User.Identity.UserName
尝试以下方法:
var username = User.Identity.Name
What you want to do is consult the HttpContext: 您要做的是查询HttpContext:
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx http://msdn.microsoft.com/zh-CN/library/system.web.httpcontext.user.aspx
It will contain all of the information about the currently logged in user. 它将包含有关当前登录用户的所有信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.