System.Web - 文件不存在

时间:2014-02-19 00:42:35

标签: c# asp.net .net

这个问题更多是出于好奇而不是其他任何问题。方案是,我提供了一些代码,让我知道我的ASP.Net内部网门户中是否存在任何错误。绝对没有问题,为了以防万一,更多的是积极主动,以防万一。

长话短说,我在Global.asax.cs中添加了这段代码:

protected void Application_Error(object sender, EventArgs e) {
    try {
        Exception ex = Server.GetLastError();

        if (ex != null) {
            MailMessage message = new MailMessage("a@company.com.au", "me@company.com.au");
            message.Subject = @"Error";
            message.Body = string.Format(@"<html><body>Unhandled error on: {0} <br/> {1} <br/> {2}",ex.Source.ToString(),ex.Message,ex.ToString ());
            message.IsBodyHtml = true;

            SmtpClient client = new SmtpClient("server.company.com.au");
            client.Send(message);
            message.Dispose();
            client.Dispose();
        }
    } catch (Exception) { }
}

我一直在电子邮件中收到此错误消息:

  

未处理的错误:System.Web文件不存在。   System.Web.HttpException(0x80004005):文件不存在。在   System.Web.StaticFileHandler.GetFileInfo(字符串   virtualPathWithPathInfo,String physicalPath,HttpResponse response)   在System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext   context,String overrideVirtualPath)at   System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context,   AsyncCallback回调,对象状态)   System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,   布尔和放大器; completedSynchronously)

我很难过。我不知道这个错误来自哪里,我仍在努力找到它。它没有以任何方式影响网站的任何方面。我相信这个错误会在之前出现,因为我所做的只是添加上面的代码。我正在使用.Net Farmework 4。

有人知道这是什么吗?

2 个答案:

答案 0 :(得分:1)

对于您的所有错误录制,我强烈推荐ELMAH。易于实施,它可以在发生某些错误时通过电子邮件发送给您

还可以节省您创建本土解决方案的时间。

答案 1 :(得分:-1)

请检查您的母版页引用的遗失文件或图像。 要捕获错误,请将以下错误处理程序添加到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);
    }
}

有些时候这个问题与丢失文件favicon.ico

有关