Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 97271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:58:23+00:00 2026-05-10T23:58:23+00:00

In my applications, I often have to use relative paths. For example, when I

  • 0

In my applications, I often have to use relative paths. For example, when I reference JQuery, I usually do so like this:

<script type='text/javascript' src='../Scripts/jquery-1.2.6.js'></script> 

Now that I’m making the transition to MVC, I need to account for the different paths a page might have, relative to the root. This was of course an issue with URL rewriting in the past, but I managed to work around it by using consistent paths.

I’m aware that the standard solution is to use absolute paths such as:

<script type='text/javascript' src='/Scripts/jquery-1.2.6.js'></script> 

but this will not work for me as during the development cycle, I have to deploy to a test machine on which the app will run in a virtual directory. Root relative paths don’t work when the root changes. Also, for maintenance reasons, I cannot simply change out all the paths for the duration of deploying the test – that would be a nightmare in itself.

So what’s the best solution?

Edit:

Since this question is still receiving views and answers, I thought it might be prudent to update it to note that as of Razor V2, support for root-relative urls is baked in, so you can use

<img src='~/Content/MyImage.jpg'> 

without any server-side syntax, and the view engine automatically replaces ~/ with whatever the current site root is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:58:24+00:00Added an answer on May 10, 2026 at 11:58 pm

    Try this:

    <script type='text/javascript' src='<%=Url.Content('~/Scripts/jquery-1.2.6.js')%>'></script> 

    Or use MvcContrib and do this:

    <%=Html.ScriptInclude('~/Content/Script/jquery.1.2.6.js')%> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this mostly applies to web applications, since you often see things like
(Not related to versioning the database schema) Applications that interfaces with databases often have
In my Windows Forms applications I often put the controls' text data (form title,
I have a type alias in my code like so: type Time = Double
Often times in applications I have a property that would normally .animate(), but every
I often find myself using several programming languages when making .NET applications. Usually C++/CLI
I often need the different parts of my applications to have their own special
I have a UITabBar + UINavigationController application which often needs data from the internet.
Have a n-tire web application and search often times out after 30 secs. How
Using an ORM approach in applications can often lead to the scenario where you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.