Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   ASP.Net (http://www.xtremevbtalk.com/asp-net/)
-   -   Exception: File does not exist (http://www.xtremevbtalk.com/asp-net/325984-exception-file-exist.html)

an_ezfriend 05-28-2013 10:05 AM

Exception: File does not exist
 
I have a default.aspx page in my subfolder (Document) which uses the Main.Master template on the root folder. The Main.Master template reference a logo in the IMAGES folder. Each time I navigate to the subfolder (or any subfolders), I always get the exception below which the default.aspx in the subfolder is trying to find images/logo.png.

File does not exist. http://localhost:2079/Document/images/logo.png

I appreciate your inputs.

Main.Master (root)
<a href="default.aspx" runat="server"><img id="x_company_logo" src="images/logo.png" runat="server" border="0"/>

Root struction
Main.Master
images/logo.png
Document/default.aspx
--------------------------------------------------------------------------
Exception TYpe
HttpException

Message
File does not exist.

Stack Trace
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApp lication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

PlausiblyDamp 05-28-2013 01:15 PM

The problem is that the src attribute is being resolved relative to the page, not relative to the master page.

You could try modifying the <img> tag so it looks like
Code:

<img src="<%=Request.ApplicationPath%>/Images/logo.png" />
This should then always resolve to an absolute path based on the application root folder.

an_ezfriend 05-28-2013 02:59 PM

I tried that, but the Main.Master template just render it as is. Through further search on the net, I came across this page http://www.codeproject.com/Articles/...sp-net-beginne, but I still no able to resolved the exception.

The logo display fine, just that I keep getting the exception because when the page load, it tries to reference document/images/logo.png rather than ../images/logo.png or ~/images/logo.png

For now -- since I know that the logo will always going to be at a location, I just hard code the full path to the website.

Very frustrated for simple thing.

PlausiblyDamp 05-28-2013 03:54 PM

Quote:

Originally Posted by an_ezfriend (Post 1401764)
I tried that, but the Main.Master template just render it as is.

Is the string being rendered as a literal into the html or if you look at the source is it rendering an <img> tag?

Could you post the line from the master and also the resulting html? The code I posted should correctly render the root of the application as part of the src="" attribute on the element.

Are you also getting an exception thrown from the code behind? If so what code is throwing the exception?

an_ezfriend 06-03-2013 08:02 AM

Sorry for the late response and thank you for your help. The code above is a straight copy from the page source. I also post the exception error on the original post, but here it is again.

--------------------------------------------------------------------------
Exception TYpe
HttpException

Message
File does not exist.

Stack Trace
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApp lication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

PlausiblyDamp 06-03-2013 08:36 AM

That isn't giving any more information about where the error is occurring though, if you run your application under a debugger is it throwing an exception anywhere or entering into break mode?

Is there anywhere in your code you are referring to this image path?

an_ezfriend 06-04-2013 05:27 PM

My logo reference on the markup of my master page as follow:
Code:

<asp:Image ID="Image1" runat="server" ImageUrl="~/images/logow.png" height="60px" Width="171px"/>
I walk through the code, the default.aspx in the subfolder loaded fine, then it went through the Page_Load event in the master page fine. Right after it exit the master page Page_Load event, it goes into the Application_Error in my global.asax. That's where I capture the error. The error exception above was capture using Server.GetLastError.

Thanks.


All times are GMT -6. The time now is 09:04 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.