简体   繁体   English

使用ADFS时在ELMAH中丢失用户信息

[英]Losing USER information in ELMAH when using ADFS

I have an MVC web application using ELMAH to log unhandled exception. 我有一个使用ELMAH记录未处理异常的MVC Web应用程序。 I'm now moving from windows authentication to ADFS authentication. 我现在正从Windows身份验证转移到ADFS身份验证。 The application has been adapted and is working fine. 该应用程序已经过修改,并且可以正常运行。 However now when I check the error, the user information is not there anymore. 但是现在当我检查错误时,用户信息不再存在。 Which makes sense as ELMAH is using the context identity and not the claims to retrieve this info. 这很有意义,因为ELMAH使用上下文身份而不是声明来检索此信息。 Does anyone of you have an idea how I could do to get this information logged again? 你们当中有人知道我该怎么做才能再次记录此信息吗?

You can enrich ELMAH errors using error filtering hook if you can accept a small hack. 如果您可以接受小技巧,则可以使用错误过滤钩子丰富ELMAH错误 In short, you need to implement the ErrorLog_Filtering method in the Global.asax.cs file: 简而言之,您需要在Global.asax.cs文件中实现ErrorLog_Filtering方法:

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
    var httpContext = args.Context as HttpContext;
    if (httpContext != null)
    {
        var error = new Error(args.Exception, httpContext);
        error.User = GetUserFromDatabase();
        ErrorLog.GetDefault(httpContext).Log(error);
        args.Dismiss();
    }
}

In the example, I update the User property with the value of a dummy method. 在示例中,我User虚拟方法的值更新了User属性。 How you want to implement this depends on how you would get the currently logged in user from ADFS. 您要如何实现它取决于您如何从ADFS获取当前登录的用户。 Finally, I log the error again and dismiss the initial (user-less) error. 最后,我再次记录该错误并消除了最初的(少用户)错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM