using System; using System.Web; namespace GLSS.Components.HttpModules { public class ExceptionModule : System.Web.IHttpModule { private void OnError(object sender,EventArgs e) { HttpContext context = HttpContext.Current; //get the last error Exception ex = context.Server.GetLastError(); if(ex.InnerException.GetType().ToString() == "CSLA.DataPortalException") ex = ex.InnerException;
这是我的Exception转换为String
HttpContext.Current.Server.GetLastError().Message "File does not exist." HttpContext.Current.Server.GetLastError().StackTrace " at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo,String physicalPath,HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context,AsyncCallback callback,Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)"
如何确定导致此错误的代码行?我试图将我的Debug选项设置为在发生错误时中断,但事实并非如此,我仍然最终在ONERROR全局处理程序中.
有一件事是我看到代码假定会有一个内部异常,这似乎是NULL并导致处理程序中的第二个错误.
我假设错误发生在编译代码的某处.我检查了Web.Config,其中提到的唯一路径是一个日志路径,这似乎有效,并且日志记录似乎正在工作.
更新
我在这里找到了一些其他信息:
How to solve exception “File does not exist”?
当我在立即窗口中检查时:
? HttpContext.Current.Request.Url.ToString() "http://localhost:2322/favicon.ico"
解决方法
:
In the absence of a link with the icon keyword,for documents obtained
over HTTP or HTTPS,user agents may instead attempt to fetch and use
an icon with the absolute URL obtained by resolving the URL
/favicon.ico against the document’s address,as if the page had
declared that icon using the icon keyword.
您看到异常的原因是配置为使用托管/集成管道模式的Web开发服务器或IIS通过Global.asax放置所有请求(包括错误).
您可以尝试通过创建以下关于favicon的虚拟链接来阻止浏览器发出请求:
<html> <head> <link rel="shortcut icon" href="#" /> ... </head> ... </html>
您也可以尝试以下方法之一:
routes.IgnoreRoute( “的favicon.ico”);
甚至更多的扩展版本:
routes.IgnoreRoute(“{* favicon}”,new {favicon = @“(.* /)?favicon.ico(/.*)?”});>为自己创建一个空文件>通过检查404的HttpException.GetHttpCode()和/((System.Web.HttpApplication)Sender)./texti.ico的.Context.Request.Url来筛选出错误.