Click here to Skip to main content
13,557,543 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 24 Feb 2010
Licenced CPOL

URL Routing and Stylesheets/Javascript

, 24 Feb 2010
Rate this:
Please Sign up or sign in to vote.
When working with the new URL routing portion of the ASP.NET 4.0, there is a gotcha that needs to be worked around.Assume a website with the following structure:~/Images/header.jpg~/Stylesheets/style.css~/Scripts/scripts.js~/Driver/Details.aspx~/Default.aspxAlso assume you...
When working with the new URL routing portion of the ASP.NET 4.0, there is a gotcha that needs to be worked around.

Assume a website with the following structure:


Also assume you use URL routing to change the structure of the page
/Driver/Details/{CustomerNumber} maps to ~/Driver/Details.aspx

When including the <script> and <link> tags in your details.aspx page, if you use the normal "../Stylesheets/style.css", then the stylesheets wont load, nor will the scripts because the page would be looking for "/Driver/Stylesheets/style.css".

Instead, use the <%= ResolveClientURL("~/Stylesheets/style.css") %> method to define the source of the resource.

<link href='<%= ResolveClientUrl("~/StyleSheets/ui.tabs.css") %>' rel="stylesheet"

    type="text/css" />
<pre lang="xml"><script src='<%= ResolveClientUrl("~/Scripts/ui.core.js") %>' type="text/javascript"></script>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Stephen Inglish
Software Developer (Senior) Harland Financial Solutions
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questionjust amazing Pin
trivas1119-May-15 16:07
membertrivas1119-May-15 16:07 
GeneralExcellent! You are the first one who solves this =D Exactl... Pin
Vlenno15-Nov-10 8:03
memberVlenno15-Nov-10 8:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 24 Feb 2010
Article Copyright 2010 by Stephen Inglish
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid