gpt4 book ai didi

c# - 检索 REMOTE_USER 服务器变量时出现异常

转载 作者:太空宇宙 更新时间:2023-11-03 14:21:38 26 4
gpt4 key购买 nike

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

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

身份验证由 IIS 使用基本身份验证(域 Controller 上的 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

我们重新启动此应用程序的应用程序池后,问题解决了大约一天。

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

谢谢!

最佳答案

让框架为您完成肮脏的工作怎么样?

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

关于c# - 检索 REMOTE_USER 服务器变量时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5193925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com