简体   繁体   中英

ResolveUrl inserts extra quote

I'm writing my first MVC2 app. I've got my master page working beautifully, and when I run it locally it functions exactly like I want it to.

My problem is that I'm deploying it on a server that has a whole bunch of Applications. ResolveUrl seems to be misbehaving. I get the correct path, but for whatever reason something is inserting an extra quote, or dropping the quotes I have.

Here's my <link> :

<link href='<%= ResolveUrl("~/Content/Site.css") %>' rel="stylesheet" type="text/css"/>

What comes out (client side, after ASP.NET is through with it):

<link href=/vcdemo/PhotoManager/Content/Site.css" rel="stylesheet" type="text/css" />

Obviously it's not what I want. When I correct the quotes in Firebug the site displays correctly.

Any ideas?

You should be using the Url.Content helper:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css"/>

Also as it seems that you are using the WebForms view engine make sure you have removed any runat="server" attributes that might be present on the <head> tag.

ResolveUrl and runat="server" are legacy stuff and should not be used in an ASP.NET MVC application.

Since you say this is MVC, you should try and use a helper

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM