我试图了解发生了什么错误将我发送到 Global ASAX OnError 处理程序。
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;
这是我的异常转换为字符串
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)"
如何确定哪一行代码导致了此错误?我尝试将调试选项设置为在错误发生时中断,但它没有,我仍然处于 ONERROR 全局处理程序中。
一件事是我看到代码假设将出现内部异常,并且这似乎是 NULL 并且在处理程序中导致第二个错误。
我假设错误发生在编译代码中的某个地方。我检查了 Web.Config,唯一提到的路径是日志路径,这似乎有效并且日志记录似乎正在工作。
Update我在这里找到了一些额外的信息:
如何解决“文件不存在”异常? https://stackoverflow.com/questions/3705057/how-to-solve-exception-file-does-not-exist
当我在“立即”窗口中检查此内容时:
? HttpContext.Current.Request.Url.ToString()
"http://localhost:2322/favicon.ico"
然而,令我困惑的是,我使用“在文件中查找”搜索整个解决方案以查找 favicon.ico,但没有看到任何参考。
当我没有看到图标文件的引用时,为什么会出现找不到图标文件的错误?我猜有些程序集正在使用它?但为什么它要在网络根目录中寻找它呢?