views:

14

answers:

1

Is there any way to use ASP.NET's 'web application root' operator ~ in a script tag? If not, is there any way to mimic such behavior?

My application uses nested master pages for different sub directories; A content page uses its directory-specific master page, which uses the root master page. I'd like to be able to include my <script> tags in the root master page, so I'm not repeating code all over the place, but since I don't necessarily know the depth of the path for any given content page, I can't reliably provide paths to the scripts folder.

I considered using paths in the form /scripts/jquery.js, but since the Visual Studio development server starts the application in a subdirectory of the server root, this will not translate well to the live server. To illustrate:

<!-- dev server path -->
<script type="text/javascript" src="/my_project/scripts/jquery.js"></script>

<!-- live server path -->
<script type="text/javascript" src="/scripts/jquery.js"></script>

You can, of course see the issue. Since I am not the only developer on the project, I have very little control over what happens in the "go live" process; otherwise, it could just be a matter of removing /my_project in the "go live" process.

A: 

There are some possible cases on that.

1) For large project use the local iis5.1 or other local iis, and not the VS web that runs.

2) You can avoid the first spash and use relative paths... eg:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="../scripts/jquery.js"></script>

so you do not force him to start from beggining.

3) You can place a literal control there and just render the script tag on Page_Load with the correct path every time

4) and you can just render the src on page

<script type="text/javascript" src="<%=ResolveUrl("~/scripts/jquery.js")%>" ></script>

I am using the 1 and 3.

Aristos
Wow, that's a lot of options! Thanks! I'm settling on number 4 for now... it seems the easiest to implement.
Ryan Kinal