<p>I've started to work a bit with master pages for an ASP.net mvc site and I've come across a question.  When I link in a stylesheet on the master page it seems to update the path to the sheet correctly.  That is in the code I have</p>

<pre><code>&lt;link href="../../Content/Site.css" rel="stylesheet" type="text/css" /&gt;
</code></pre>

<p>but looking at the source once the page is fed to a browser I get</p>

<pre><code>&lt;link href="Content/Site.css" rel="stylesheet" type="text/css" /&gt;
</code></pre>

<p>which is perfect.  However the same path translation doesn't seem to work for script files.  </p>

<pre><code>&lt;script src="../../Content/menu.js" type="text/javascript"&gt;&lt;/script&gt;
</code></pre>

<p>just comes out as the same thing.  It still seems to work on a top level page but I suspect that is just the browser/web server correcting my error.  Is there a way to get the src path to be globbed too?    </p>

[{'answer_id': 64586, 'author': 'Iain Holder', 'author_id': 1122, 'author_profile': 'https://Stackoverflow.com/users/1122', 'pm_score': 0, 'selected': False, 'text': '<p>Use this instead:</p>\n\n<pre><code>&lt;link href="~/Content/Site.css" rel="stylesheet" type="text/css" /&gt;\n</code></pre>\n'}, {'answer_id': 66376, 'author': "Dane O'Connor", 'author_id': 1946, 'author_profile': 'https://Stackoverflow.com/users/1946', 'pm_score': 1, 'selected': False, 'text': '<p>Make an extension method. Here\'s a method:</p>\n\n<pre><code>public static string ResolveUrl(this HtmlHelper helper, string virtualUrl)\n{\n    HttpContextBase ctx = helper.ViewContext.HttpContext;\n    string result = virtualUrl;\n\n    if (virtualUrl.StartsWith("~/"))\n    {\n        virtualUrl = virtualUrl.Remove(0, 2);\n\n        //get the site root\n        string siteRoot = ctx.Request.ApplicationPath;\n\n        if (!siteRoot.EndsWith("/"))\n            siteRoot += "/";\n\n        result = siteRoot + virtualUrl;\n    }\n    return result;\n}\n</code></pre>\n\n<p>You can then write your script ref like:</p>\n\n<pre><code>&lt;script type="text/javascript" src="&lt;%= Html.ResolveUrl("~/Content/menu.js")%&gt;"&gt;&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 66632, 'author': 'Hrvoje Hudo', 'author_id': 1407, 'author_profile': 'https://Stackoverflow.com/users/1407', 'pm_score': 0, 'selected': False, 'text': '<p>or you can use BASE tag in you HEAD section of page. All you links then are relative to location entered in "base" tag, and you don\'t have to use "../../" and "~" stuff. Except links in CSS files (background url,etc), where links are relative to location of css file. </p>\n'}, {'answer_id': 169158, 'author': 'Shawn Miller', 'author_id': 247, 'author_profile': 'https://Stackoverflow.com/users/247', 'pm_score': 3, 'selected': True, 'text': '<pre><code>&lt;script src="&lt;%= ResolveClientUrl("~/Content/menu.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/64559', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/361/']