【问题标题】:Getting the value of Request.ServerVariables(“LOGON_USER”)获取 Request.ServerVariables(“LOGON_USER”) 的值
【发布时间】: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


【解决方案1】:

终于修好了。如果您想使用Request.ServerVariables(“LOGON_USER”),您应该在 IIS 中禁用匿名访问

PS:禁用匿名访问有一些副作用,例如infinite login redirect loop

【讨论】:

猜你喜欢
  • 2015-07-01
  • 2013-03-16
  • 1970-01-01
  • 1970-01-01
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-30
相关资源
最近更新 更多