Exception while retrieving REMOTE_USER server variable
We have a ashx http handler that retrieves the REMOTE_USER variable from the ServerVariables during the ProcessRequest.
public void ProcessRequest(HttpContext context)
{
if (context.Request.ServerVariables["REMOTE_USER"].Contains("\\")) // exception is thrown here
...
The authentication is handled by IIS using basic authentication (windows accounts on domain controller).
For some users this starts fail开发者_开发技巧ing (after working fine for a few hours) and throwing the following exception:
[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
After we restart the application pool of this application the problem is resolved for about a day.
Any ideas? Should we use another server variable to retrieve the user name?
Thanks!
How about letting the framework do your dirty work for you?
context.User.Identity.Name
should contain the very same data.
精彩评论