ELMAH - 使用自定义错误页面收集用户反馈 [英] ELMAH - Using custom error pages to collecting user feedback

查看:96
本文介绍了ELMAH - 使用自定义错误页面收集用户反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在第一次使用ELMAH,但有一个要求需要满足,我不知道如何实现...

I'm looking at using ELMAH for the first time but have a requirement that needs to be met that I'm not sure how to go about achieving...

基本上,我将配置ELMAH在asp.net MVC下工作,并将其发送到数据库时发生错误。最重要的是,当发生错误时,我将使用customErrors将用户引导到友好的消息页面。相当标准的东西...

Basically, I am going to configure ELMAH to work under asp.net MVC and get it to log errors to the database when they occur. On top of this I be using customErrors to direct the user to a friendly message page when an error occurs. Fairly standard stuff...

要求是在这个自定义错误页面上,我有一个表单,使用户可以提供额外的信息,如果他们希望。现在出现这个问题的原因是,在这一点上,错误已经被记录下来了,我需要将用户的错误与用户反馈相关联。

The requirement is that on this custom error page I have a form which enables to user to provide extra information if they wish. Now the problem arises due to the fact that at this point the error is already logged and I need to associate the loged error with the users feedback.

通常,如果我是使用我自己的自定义实现,在我记录错误后,我会将错误的ID传递到自定义错误页面,以便可以进行关联。但是,由于ELMAH的工作原理,我认为这是不可能的。

Normally, if I was using my own custom implementation, after I log the error I would pass through the ID of the error to the custom error page so that an association can be made. But because of the way that ELMAH works, I don't think the same is quite possible.

所以我想知道人们怎么会这么认为。 ...

Hence I was wondering how people thought that one might go about doing this....

欢呼

更新:

我的解决方案如下:

public class UserCurrentConextUsingWebContext : IUserCurrentConext
{
    private const string _StoredExceptionName = "System.StoredException.";
    private const string _StoredExceptionIdName = "System.StoredExceptionId.";

    public virtual string UniqueAddress
    {
        get { return HttpContext.Current.Request.UserHostAddress; }
    }

    public Exception StoredException
    {
        get { return HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] as Exception; }
        set { HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] = value; }
    }

    public string StoredExceptionId
    {
        get { return HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] as string; }
        set { HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] = value; }
    }
}

然后当发生错误时,我有一些像这在我的Global.asax中:

Then when the error occurs, I have something like this in my Global.asax:

public void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
{
    var item = new UserCurrentConextUsingWebContext();
    item.StoredException = args.Entry.Error.Exception;
    item.StoredExceptionId = args.Entry.Id;
} 

然后你以后可以通过

    var item = new UserCurrentConextUsingWebContext();
    var error = item.StoredException;
    var errorId = item.StoredExceptionId;
    item.StoredException = null;
    item.StoredExceptionId = null;

注意,这不是100%的完美,因为它可能对同一个IP有多个请求有同时出现错误。但是发生这种情况的可能性很大。这个解决方案是独立于会话的,在我们的例子中这是很重要的,也有一些错误可能导致会话被终止等等。因此,为什么这种方法对我们很好的工作。

Note this isn't 100% perfect as its possible for the same IP to have multiple requests to have errors at the same time. But the likely hood of that happening is remote. And this solution is independent of the session, which in our case is important, also some errors can cause sessions to be terminated, etc. Hence why this approach has worked nicely for us.

推荐答案

ErrorLogModule 提供了一个 已记录 您可以在 Global.asax 中处理事件,您可以通过 HttpContext.Items 集合到您的自定义错误页面。如果您在 web.config ErrorLog 下注册了 ErrorLogModule c>然后在 Global.asax 中的事件处理程序将如下所示:

The ErrorLogModule in ELMAH (version 1.1 as of this writing) provides a Logged event that you can handle in Global.asax and which you can use to communicate details, say via HttpContext.Items collection, to your custom error page. If you registered the ErrorLogModule under the name ErrorLog in web.config then your event handler in Global.asax will look like this:

void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)  
{ 
    var id = args.Entry.Id
    // ...  
}

这篇关于ELMAH - 使用自定义错误页面收集用户反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆