I’ve setup a web application under a website using information from IIS.Net – Understanding Site, Applications and Virtual Directories
Below is what they say regarding applications.
An application is a group of files that delivers content or provides services over protocols, such as HTTP. When you create an application in IIS, the application’s path becomes part of the site’s URL.
That’s great; exactly what I want; however…the application path is not resolving properly for script files, css and a web service I have in the application.
For http://site_name/application_name
<img src="/Content/images/smiley.png" alt="smiley face" /></a>
resolves to
src="/site_name/Content/images/smiley.png"
instead of
src="/application_name/Content/images/smiley.png"
As a work-around I’ve wrapped the paths I was using withe @Url.Content() helper. Not the prettiest solution, but it’s working.
<img src="@Url.Content("~/Content/images/smiley.png")" alt="smiley face" /></a>
Is there a way to fix this in IIS?
Using
@Url.Contentis the right way here IMO. It then makes the links work regardless of how a developer is setup on their machine (running the dev server, or using IIS).I’m not sure if there’s a way to deal with it in IIS, maybe a URL rewrite rule, but it won’t help with consistency across development machines.
Edit: You could deploy the site to the root of the site in IIS, as opposed to a virtual directory, but that is only a good solution if you’re only going to be hosting this single site.