Routing with static ressource files (.js, .css)


I have some troubles using Friendly Urls and static ressources like .js or .css files.
It is the same as described here:

It happens that if you use FriendlyUrl.Href("~/Details", "param") to include the first parameter in the URL you get the URL "/Details/param?key=value".
For all the files used in script tags like src="js/details.js" the request is sent to the page with "js" and "details.js" as URL segments with the request URL "Details/js/details.js" instead of loading the file from the directly with "js/details.js".

If you don't use any parameter after the page name it works fine. Is there any solution without rewriting all references in the project?
Closed Jul 31, 2013 at 4:39 PM by damianedwards


damianedwards wrote Jul 31, 2013 at 4:38 PM

This is by design. By adding the parameter to the URL it appends a new path segment. The browser will always make relative requests from the relative path segment, in this case ~/Details/ (it walks back from the end of the URL ~/Details/param until it reaches a forward slash).

To fix you should ensure you reference static resources using their app-relative root path, which can be easily resolved using ResolvePath("~/js/details.js")