【问题标题】:Exception while retrieving REMOTE_USER server variable检索 REMOTE_USER 服务器变量时出现异常
【发布时间】:2011-03-04 12:49:20
【问题描述】:

我们有一个 ashx http 处理程序,它在 ProcessRequest 期间从 ServerVariables 检索 REMOTE_USER 变量。

public void ProcessRequest(HttpContext context)
{
    if (context.Request.ServerVariables["REMOTE_USER"].Contains("\\")) // exception is thrown here
    ...

身份验证由 IIS 使用基本身份验证(域控制器上的 Windows 帐户)处理。

对于某些用户,这开始失败(在正常工作几个小时后)并引发以下异常:

[IdentityNotMappedException: Some or all identity references could not be translated.]
   System.Security.Principal.SecurityIdentifier.Translate(IdentityReferenceCollection sourceSids, Type targetType, Boolean forceSuccess) +7608560
   System.Security.Principal.SecurityIdentifier.Translate(Type targetType) +100
   System.Security.Principal.WindowsIdentity.GetName() +164
   System.Security.Principal.WindowsIdentity.get_Name() +31
   System.Web.HttpRequest.CalcDynamicServerVariable(DynamicServerVariable var) +8726378
   System.Web.HttpServerVarsCollection.GetSimpleServerVar(String name) +424
   System.Web.HttpServerVarsCollection.Get(String name) +8634072
   System.Collections.Specialized.NameValueCollection.get_Item(String name) +7
   Some.Namespace.AHttpHandler.ProcessRequest(HttpContext context) in c:\afolder\AHttpHandler.ashx.cs:34
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 

在我们重新启动这个应用的应用池后,问题解决了大约一天。

有什么想法吗? 我们应该使用另一个服务器变量来检索用户名吗?

谢谢!

【问题讨论】:

  • The authentication is handled by IIS using basic authentication 是这样吗?但基本身份验证是通过 HTTP 标头传递用户名密码。你的意思是windows authentication
  • 是的,这是基本身份验证,它使用来自 Active Directory 的用户:Windows 身份。

标签: c# asp.net iis


【解决方案1】:

让框架为你做脏活怎么样?

context.User.Identity.Name 应该包含完全相同的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 2014-12-18
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多