curiouswebster
asked on
Finding missing filename on "File Does Not Exist" exception
I catch the exception in the Global.asax.Application_Er ror() function, and extract the
exception, log it and redirect to the proper page thusly: (I use MVC)
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
LogException(exception);
Response.Clear();
Server.ClearError();
Response.Redirect(String.F ormat("/Er ror/Generi c/?outputS tr={0}", exception.Message));
}
BUT I CAN NOT FIND THE FILENAME that's missing.
I have browsed Google and found this post, which was never answered completely.
http://www.codeguru.com/forum/showthread.php?t=508023
I do not want to install some program to find the filename, as was suggested. It's in either the exceptionor Server, since I saw it once while debugging. But I was to grab the filename and log that to the exception log file.
Can anyone tell me how to find it?
Thanks,
newbieweb
exception, log it and redirect to the proper page thusly: (I use MVC)
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
LogException(exception);
Response.Clear();
Server.ClearError();
Response.Redirect(String.F
}
BUT I CAN NOT FIND THE FILENAME that's missing.
I have browsed Google and found this post, which was never answered completely.
http://www.codeguru.com/forum/showthread.php?t=508023
I do not want to install some program to find the filename, as was suggested. It's in either the exceptionor Server, since I saw it once while debugging. But I was to grab the filename and log that to the exception log file.
Can anyone tell me how to find it?
Thanks,
newbieweb
ASKER
and the InnerException is null.
I think I got the new exception when I ran this line with a null fnfException, not when I typecasted it, as I has said on my previous post.
string fileNameStr = fnfException.FileName;
I think I got the new exception when I ran this line with a null fnfException, not when I typecasted it, as I has said on my previous post.
string fileNameStr = fnfException.FileName;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your code works fine, but the value for fex is still null. So the filename remains null. This must not be a FileNotFoundException.
ASKER
In the code I'm using to throw the exception, it's JQuery looking for the file (which I intentionally renamed) and the Exception gets pulled out in the Application_Error() function via the following call:
Exception exception = Server.GetLastError();
Exception exception = Server.GetLastError();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added this line:
string expStr = exception.ToString();
but on the next line, I see nothing whenI put the mouse of expStr. When I put the mouse over exceptionI see
{"File does not exist."}
That tells me the expStr is null or (more likely) undefined.
string expStr = exception.ToString();
but on the next line, I see nothing whenI put the mouse of expStr. When I put the mouse over exceptionI see
{"File does not exist."}
That tells me the expStr is null or (more likely) undefined.
ASKER
We also have these available:
object sender, EventArgs e
those are the inputs into Global.asax.Application_Er ror(), as you can see in the original post.
newbieweb
object sender, EventArgs e
those are the inputs into Global.asax.Application_Er
newbieweb
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Undefined. See attached...
Exception.PNG
Exception.PNG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got a value:
System.Web.HttpException (0x80004005): File does not exist.
at System.Web.StaticFileHandl er.GetFile Info(Strin g virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandl er.Process RequestInt ernal(Http Context context, String overrideVirtualPath)
at System.Web.DefaultHttpHand ler.BeginP rocessRequ est(HttpCo ntext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication .CallHandl erExecutio nStep.Syst em.Web.Htt pApplicati on.IExecut ionStep.Ex ecute()
at System.Web.HttpApplication .ExecuteSt ep(IExecut ionStep step, Boolean& completedSynchronously)
System.Web.HttpException (0x80004005): File does not exist.
at System.Web.StaticFileHandl
at System.Web.StaticFileHandl
at System.Web.DefaultHttpHand
at System.Web.HttpApplication
at System.Web.HttpApplication
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This does get added:
exception.Data.Add("Url", app.Context.Request.Url);
I broke this up to see exactly what wass happening:
string url = null;
if ( exception.Data.Contains("U rl"))
{
url = exception.Data["Url"].ToSt ring();
}
but the value for url is not defined, like outputStr was before.
exception.Data.Add("Url", app.Context.Request.Url);
I broke this up to see exactly what wass happening:
string url = null;
if ( exception.Data.Contains("U
{
url = exception.Data["Url"].ToSt
}
but the value for url is not defined, like outputStr was before.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS! THIS WORKS!!!
ASKER
FileNotFoundException fnfException = exception as FileNotFoundException;
and
FileNotFoundException fnfException = (FileNotFoundException)ex;
so I could do this:
string fileNameStr = fnfException.FileName;
but got an exception in both cases when I tried to typecast to FileNotFoundException
Is there a proper way to do this?
newbieweb