Asp – Classic ASP Server.MapPath not working properly

asp-classic

The site I'm working on is done in Classic ASP, and I'm trying to do it as best as possible. I've abstracted it out into a Rails-like directory structure:

app_name
 - app
   - includes
     - helpers
     - lib
     - partials
  - public
    - stylesheets
    - images
    - javascripts

I've created some Rails-like helpers, for example:

Function ImageTag(ByVal imageFileName, ByVal altText)
  path = Server.MapPath(IMAGE_ROOT & imageFileName & ".jpg")
  ImageTag = "<img src=""" & path & """ title=""" & altText & """ alt=""" & altText & """ />"
End Function

Which is used thusly:

<%= ImageTag("my_pic") %>

With "IMAGE_ROOT" defined as "../public/images/" in a config file. I'm doing development on XP so the site is set as a virtual directory. However, the image won't load on the webpage at all. It's displaying the right path to it, because I can copy/paste it into my browser and view the image – it just won't display on the page for some reason. The same thing goes for my CSS stylesheet – the path is right but the page isn't rendering it at all.

Any suggestions?

Best Answer

An excellent tool to use when troubleshooting these types of issues is Fiddler. It will show you the calls and responses directly bewtween your web browser and the server. It works out of the box with IE and FireFox support is just a config setting away.

I'ver personally used Fiddler to track down image load issues, CSS problems, caching issues, redirect errors, and even have used it to tamper with URL variables to try breaking/hacking my sites.

Fiddler Website

Related Topic