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

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

问题描述

嘿,伙计们
我期待在使用ELMAH首次,但有一个需要得到满足,我不知道如何去实现的要求...

Hey guys 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...

要求是,这种自定义错误页上我有一个表格使用户以提供额外的信息,如果他们的愿望。现在问题的出现是由于这样的事实,在此点错误已经登录,我需要的loged误差与用户反馈相关联。

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....

干杯

更新:

我对这个问题的解决方案如下:

My solution to the problem is as follows:

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;
} 

然后在任何你以后都可以通过

Then where ever you are later you can pull out the details by

    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.

推荐答案

的<一个href=\"http://$c$c.google.com/p/elmah/source/browse/tags/REL-1.1/src/Elmah/ErrorLogModule.cs\"><$c$c>ErrorLogModule在ELMAH(1.1版本写这篇文章的)提供了一个<一个href=\"http://$c$c.google.com/p/elmah/source/browse/tags/REL-1.1/src/Elmah/ErrorLogModule.cs#45\"><$c$c>Logged事件,你可以在的Global.asax 处理,哪些是你可以用它来传达信息,通过<一说href=\"http://msdn.microsoft.com/en-us/library/system.web.httpcontext.items.aspx\"><$c$c>HttpContext.Items收藏,您的自定义错误页。如果您注册了 ErrorLogModule 下的 web.config中的名称错误日志 然后的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天全站免登陆