I've taken over the code of a website from someone else to finish off and have hit the issue that every time I load a page, I get a 'File Does Not Exist' exception caught in the Application_Error handler in my Global.asax file.
I was curious what it was, so have trie开发者_StackOverflow社区d creating brand new solutions with both a Web Site and Web Application, both with and without a Master Page and a single .aspx page - both had the same problem.
This is using VS2010 and .NET 3.5, on Windows 7 64-bit.
Any ideas please? The stack trace tells me absolutely nothing and the fact I'm getting it with new projects is odd.
Exception Stack Trace:
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)
The trick in figuring out which file does not exist is to use the following code in the Application_Error
method.
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
string file = HttpContext.Current.Request.Url.ToString();
string page = HttpContext.Current.Request.UrlReferrer.ToString();
}
This will retrieve the name of the file that is missing and the original page from which the request came.
What is the file name in the exception? If the file name or the path is obfuscated, then you likely have a corruption in ASP.NET temporary files. Try "clean solution" and "rebuild solution" and run it again.
Otherwise, you'll need to post more information, including the full exception message, not just the call stack. Is this happening on the default page of the site? Is the web project selected as the startup project? Is this happening in the Visual Studio web server, or IIS?
I detect my error in Application_Error within gloal.asax I also get Request.Url.ToString(), this would give you the culprit resource. For example in my app I found that the Application_Error even complains about the favicon.ico, and also if you have some files missing that you might be referencing from your css, it would get caught by the Application_Error event.
actually, check out this blog for example, talks about the same issue and using the Request.Url to discover what the resource in question is. This should help http://dotbert.loedeman.nl/httpexception-file-does-not-exist
I never got to the bottom of this sadly and an overdue rebuild of my computer sorted it.
I solved this for my situation ... turned out that the project properties had reverted back to "Use Current Page" (in VS 2010 - Project Properties | Start Options | Start Action).
The odd thing is that I had set the Start Options to "Specific Page:" -- so somewhere along the line VS 2010 lost track of it and defaulted back to "Use Current Page".
Rob.
精彩评论