When you are testing a web application in visual studio using IIS Express, you’ll be able to add a reference to a script file like this (inside an ASPX file):
However, when you are deploying the exact same application on an standard IIS server (using a web deployment package), you’ll get an missing error 404 because the browser won’t be able to resolve the url.
To fix it, I could simply remove the slash from the path:
However, this question ain’t about how to fix the link since this question has been asked and answered many time. What I would like to understand is why does IIS Express handle those url correctly while IIS Express ain’t able to? Is it question of security (ex: browser has access to you local file while working on your own computer which ain’t the case on remote server) or is it a matter of settings the doesn’t get exported in the web package?
If it is really the case, the difference comes from the fact that a relative URL beginning with / means it is relative to the host name part of the url while a relative url without the initial / is relative to the actual page folder.
In the current example, if the page is
|Server||Base Page||Relative Url||Result Url|
On a site not, another way of having both behave the same way would be to modify the project’s properties for IIS Express (or directionly the applicationHost.config file) so that it also uses a virtual directory instead of mapping directly to root.
Answered By – bkqc
Answer Checked By – Senaida (BugsFixing Volunteer)