Windows 身份验证 - Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

Windows Authentication - Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

我刚开始使用 stackify 的 Retrace 来监控我的应用程序,发现了数千个错误,它们是:

System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at System.Guid.TryParseGuidWithNoStyle
at System.Guid.TryParseGuid
at System.Guid..ctor
at System.DirectoryServices.AccountManagement.ADStoreCtx.IdentityClaimToFilter

这些错误每天发生数千次,我无法弄清楚原因。首先,我的应用程序是这样工作的:

MVC前端-使用Windows身份验证(使用RestSharp调用后端)

Web API 后端,使用从 RestSharp NTLM 身份验证传递的 Windows 身份验证。

RestSharp 包装器

    public object WebRequest<T>(string controller, Dictionary<string, string> parameters, Method apiMethod, string action)
    {
        RestClient client = new RestClient(Url + controller + "/");
        client.Authenticator = new NtlmAuthenticator();
        RestRequest request = new RestRequest(action, apiMethod);

        if (parameters != null && parameters.Count > 0)
        {
            foreach (var parameter in parameters)
            {
                request.AddParameter(parameter.Key, parameter.Value);
            }
        }

        object result = JsonToObject<T>(client.Execute(request).Content);

        return result;
    }

辅助方法

@helper Username()
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

 var username = System.Web.HttpContext.Current.User.Identity.Name.Replace(@"DOMAIN\", "");

@username
}

@helper UserFullName()
{
    using (var context = new PrincipalContext(ContextType.Domain))
    {
        var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name);
        if (principal != null)
        {
            var fullName = string.Format("{0}", principal.DisplayName);
            @fullName
        }
    }
}

关于此错误可能发生的位置或我可以做些什么来缩小错误范围的任何建议?据我在 Stackify 中所知,它似乎发生在每一页上。

有一个 FindByIdentity 的重载,允许您指定 identityValue 实际上是什么,例如

Try UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, User.Identity.Name);

由于 GUID 是此调用的有效选项,因此当您使用非特定重载时似乎存在问题并且它可能会尝试嗅探值是什么。