【发布时间】: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 身份。