views:

683

answers:

2

When building code like this:

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

or

<input type="image" src="<%=ResolveUrl("~/img/submit.png")%>" />

Should I use Url.Content or ResolveUrl()? What's the difference?

+2  A: 

Url.Content is more MVCish as it is the normal. ResolveUrl has been around since the beginning of ASP.NET.

Darin Dimitrov
@Darin Any reason to use one over the other?
Michael Haren
In an MVC application I would prefer `Url.Content`. It's kind of more unit-testable friendly.
Darin Dimitrov
+3  A: 

If you're using IIS URL Rewriting within your MVC application, e.g. internally treating http://yoursubdomain.example.com/MyController/MyAction as http://hosted.example.com/yoursubdomain/MyController/MyAction, Url.Content() will generate a correct subdomain-relative link. ResolveUrl() will generate an incorrect link in this situation.

Levi