问题描述
我创建ASP.NET MVC应用程序。我需要处理异常在两个地方。
I'm creating an ASP.NET MVC application. I need to handle exceptions in two places.
Global.asax.vb文件:
Global.asax.vb file:
Public Class MvcApplication
Inherits System.Web.HttpApplication
...
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
LogException(HttpContext.Current.Server.GetLastError(), Request)
End Sub
Shared Sub LogException(ByVal ex As Exception, ByRef r As System.Web.HttpRequest)
...
End Sub
End Class
浏览\共享\ Error.aspx文件:
Views\Shared\Error.aspx file:
<%@ Page Language="VB" Inherits="System.Web.Mvc.ViewPage(Of System.Web.Mvc.HandleErrorInfo)" %>
<script runat="server">
Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
MvcApplication.LogException(Model.Exception, Request)
End Sub
</script>
...
不过,我得到这个错误:
But I get this error:
C:\的Inetpub \ example.com \查看\共享\ Error.aspx(5):错误BC30451:名称MvcApplication未声明
我应该在哪里定义我LogException()函数,因此,它是同时从Global.asax.vb文件和Error.aspx文件访问?哪里最MVC上下的?
Where should I define my LogException() function so that it is accessible from both the Global.asax.vb file and the Error.aspx file? Where is the most MVC-ish?
推荐答案
您可能想尝试所谓ELMAH一个模块。在Scott Hanselman说:ELMAH是TiVo公司为ASP.NET错误。我现在使用它在我的ASP .NET + MVC应用程序记录错误,它就像一个魅力。安装很容易,因为所有需要的是增加线路的web.config中。你甚至可以限制谁有权查看错误日志。
You may want to try an module called ELMAH. Scott Hanselman says "ELMAH is Tivo for your ASP.NET Errors". I've am currently using it for logging errors in my ASP .NET + MVC applications and it works like a charm. Setup was easy because all that is required is adding lines to the web.config. You can even restrict who has access to view the error logs.
的
这篇关于在双方的Global.asax和Error.aspx ASP.NET MVC错误记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!