我有一个基本的ASP.NET MVC2站点,每次加载一个视图(不是局部视图)时,它都会记录一个“文件不存在”的错误。我很确定这是因为我从母版页引用了一个不存在的文件,但我不知道是哪个文件。
堆栈跟踪没有用(见下文)。有没有人有任何关于如何最好地调试它的提示?
File does not exist. : 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)
发布于 2010-09-15 04:41:03
正如你所说,这可能是你的母版页所引用的丢失的文件或图像。要捕获错误,请将以下错误处理程序添加到Global.asax
中
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex.Message == "File does not exist.")
{
throw new Exception(string.Format("{0} {1}", ex.Message, HttpContext.Current.Request.Url.ToString()), ex);
}
}
这应该会告诉您页面正在请求的资源是什么
发布于 2012-01-06 03:06:40
或者,如果是调试,只需在“即时”窗口中放入以下行即可进行检查:
?HttpContext.Current.Request.Url.ToString()
发布于 2012-02-02 07:19:16
检查CSS文件中不存在" resource_path“的url( Resource_path)。
我得到了同样的异常。在CSS文件中发现问题,其中项目中缺少图像文件,而文件系统中没有图像文件。例如,像这样的行:
background-image: url( /images/foo.png );
其中"foo.png“文件不在图像文件夹中。
您可以将最后一个异常转换为HttpException以获取HTML状态代码:
HttpException httpEx = Server.GetLastError() as HttpException;
if( httpEx != null )
httpEx.GetHttpCode(); // Will be HTML status code, 404 in this case.
但它不包含任何缺少哪个文件的信息。我通过检查页面上的每个CSS类声明是否发生了这个错误,找到了丢失的文件。
https://stackoverflow.com/questions/3705057
复制相似问题