Classic ASP Server.MapPath not working as expected
The site I am working on runs in classic ASP and I try to do it as best I can. I digressed it into a Rails-like directory structure:
app_name - app - includes - helpers - lib - partials - public - stylesheets - images - javascripts
I've created some Rails-like helpers like:
Function ImageTag(ByVal imageFileName, ByVal altText)
path = Server.MapPath(IMAGE_ROOT & imageFileName & ".jpg")
ImageTag = "<img src=""" & path & """ title=""" & altText & """ alt=""" & altText & """ />"
End Function
Used this way:
<%= ImageTag("my_pic") %>
With "IMAGE_ROOT" defined as "../public/images/" in the config file. I am doing development on XP so the site is installed as a virtual directory. However, the image doesn't load at all on the webpage. It shows the correct path to it because I can copy / paste it into my browser and view the image - it just doesn't appear on the page for some reason. The same goes for my CSS stylesheet - the path is right, but the page doesn't render it at all.
Any suggestions?
source to share
A great tool to use in troubleshooting these issues is Fiddler. It will show you the calls and responses directly in front of your web browser and server. It works in a box with IE and FireFox support - it's just a config setup.
I've personally used Fiddler to track down image loading issues, CSS issues, caching issues, redirect errors, and even used it to change urls to try and hack / hack my sites.
source to share
You are likely to run into problems related to server and web directories.
Server.MapPath
will give you when you probably need it . The browser cannot take over the first of your servers. C:\InetPub\...\public\images\my_pic.jpg
/public/images/my_pic.jpg
The image must be accessible through your domain: localhost / public / images / my_pid.jpg .
I assume that since you can view the image you are developing in the same box that supports it? If that's the case, you can view the image because it just opens as a local file by the browser. Everyone else should use HTTP-only.
source to share