Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS virtual directory and ASP.NET directory paths

The problem

I'm running into the typical virtual-directory dilemma in that you have some paths on your ASP.Net application and you deploy the app in a IIS virtual directory. Then all paths relatives to the "web root" (f.i., "/images") doesn't work because the app is in a virtual directory path.


The solutions

A. Make the "images" folder a virtual directory. This way "/images" will always exist.

B. Use "<%=Request.ApplicationPath%>/Imagenes" as the source of my images. This works great in IIS but I can't see it in design-time nor in debug-time.

This solution also include these instructions:

  • System.Web.VirtualPathUtility.ToAbsolute
  • ResolveClientUrl
  • Request.ApplicationPath

C. Use relatives paths to the current control/page. This is know exactly where the images folder is relative to my current file (without go to the root. So I would use things like "", "../", "../../" and so on.


The solution I'm looking for

Said that. I don't like these solutions. I would want a solution in the web.config file or in IIS. Some conf intruction I write in the web.config file that tells IIS where my application resides actually (virtual directory).

Any advice?

like image 570
David Elizondo Avatar asked Sep 19 '09 19:09

David Elizondo


2 Answers

Are you using the tilde (~) for your paths where you can?

~ refers to the root of the virtual Web application....

~/images for example.

like image 186
Kevin LaBranche Avatar answered Nov 14 '22 13:11

Kevin LaBranche


If it's just for css files on the client side then using the url directive makes the path relative to that of the style sheet rather than the page:

h1#title { background: url('dog.gif') no-repeat 0 0; } 

Also if you're on asp.net mvc then you have access to:

<script src="<%= Url.Content("~/scripts/new.js") %>" type="text/javascript"></script>
like image 30
Giles Roberts Avatar answered Nov 14 '22 13:11

Giles Roberts