My production environment is in a directory off the main url www.example.com/sample. Most of my URLs are resolving fine by using ~, so ~/default.aspx resolves to www.example.com/sample/default.aspx.
However, none of my javascript of css is loading correctly in production. I have the script src set to, for example, js/sample.js, and I have tried ~/js/sample.js and it does not resolve. I tried runat="server" in the <script> tag, but I got an error sometimes. I have:
<script runat="server" src="~/js/sample.js?<%= MyCode.VersionInfo.JSTag %>" type="text/javascript"></script>
Here I am tagging a version code to the end of the filename to force reload during debugging, however, with runat=server it complains about this.
I’m sure this is a common issue, and there is a standard idiom for handling it, but I can’t seem to find it. Can someone help me? When and how does the ~ get expanded, and how do people handle this type of thing?
Most likely when the web site goes to full production, it will go in without the subdirectory, so I need to handle this systematically.
what you are looking for is:
more information here