【发布时间】:2014-11-13 15:12:30
【问题描述】:
我正在尝试使用 Request.ServerVariables(“LOGON_USER”) 变量在我的 ASP.NET 页面中获取经过身份验证的用户名。它给了我一个空字符串。关于这个变量有很多话题。 The common point 正在使用 None 以外的身份验证类型并拒绝匿名访问。所以我在我的web.config 中添加了这些行:
<authentication mode="Forms"/>
<authorization>
<deny users = "?" /> <!-- This denies access to the Anonymous user -->
<allow users ="*" /> <!-- This allows access to all users -->
</authorization>
我仍然得到一个空字符串。如何获取用户名?
也试过了:
Request.ServerVariables["REMOTE_USER"];
Request.ServerVariables["UNMAPPED_REMOTE_USER"];
Request.ServerVariables["AUTH_USER"];
HttpContext.Current.User.Identity.Name;
【问题讨论】:
-
确保您已登录网站并在经过身份验证的页面中进行检查。
标签: asp.net authentication web-config authorization request.servervariables