asp.Net   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net-mvc – 如何解决异常“文件不存在”?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个基本的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)

解决方法

正如你所说,它可能是您的主页引用的缺少的文件或映像。要捕获错误,请将以下错误处理程序添加到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);
    }
}

这应该告诉你页面请求什么资源

大佬总结

以上是大佬教程为你收集整理的asp.net-mvc – 如何解决异常“文件不存在”?全部内容,希望文章能够帮你解决asp.net-mvc – 如何解决异常“文件不存在”?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。