加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 如何解决异常“文件不存在”?

发布时间:2020-12-16 00:37:34 所属栏目:asp.Net 来源:网络整理
导读:我有一个基本的ASP.NET MVC2网站,每次加载视图(而不是部分视图)时,记录一个“文件不存在”错误。我很确定这是因为我引用一个文件,从母版页,不存在,但我不知道它是哪一个。 堆栈跟踪无效(见下文)。有没有人有任何提示如何最好地调试这个? File does not
我有一个基本的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);
    }
}

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读