views:

321

answers:

4
<link href="Site.css" rel="stylesheet" type="text/css" />

This works fine from Theme.Master (Views/Themes/Blue/Theme.Master) on my local machine, but not from the hosted provider of its final home. The Theme.Master can find the css if the css is in the Content folder, in any subfolders of the Content folder, but not if the css is in the same folder as the Theme.Master.

Have I made sense?

Very Frustrated

+1  A: 

You've to use relative file references. Try this:

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

...and that should solve the problem.

Edit Since you commented that this didn't work, I looked up where I found my solution from. I got it from Lance Fisher in this blog post. In case that doesn't clear it up (since it is talking about java script files), you can also look here at a similar question that was answered previously. Hope that helps!

Nick DeVore
the result of <link href="<%= Url.Content("~/Views/Themes/Blue/Site.css") %>" rel="stylesheet" type="text/css" /> is <link href="/Views/Themes/Blue/Site.css" rel="stylesheet" type="text/css" />and that did not work. T
A: 

Have you tried using a rooted path? Such as:

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

or

<link href="/style/Site.css" rel="stylesheet" type="text/css" />

if your style sheet isn't on the root of your site.

Ben S
does not fix problem
A: 

On the hosted provider, is the app in the site root? or in a sub-folder? Does your development environment match the setup at the server in this respect? You may need to ensure you work relative to the app root, ~/

Fundamentally, this is similar to the same problem (with scripts) discussed here.

Marc Gravell
none of these suggestions, while all good, fixed the problem.
+1  A: 

Your comment on Nick's answer implies that you are trying to put a .css file in the same folder as the Theme.Master file that is under the ~/Views/ folder tree. You can't do this. The ~/Views/ tree is configured to block all HTTP requests from the web browser.

You need to put your .css file in an accessible location. The ~/Content/ folder tree is the traditional place to put a .css file. If you move your .css file there and then use this as Nick suggested, it will work:

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

For the record, it doesn't work in the Views folder because of these directives in the web.config file (note, there is a web.config file directly in the Views folder). This is just FYI. I don't advise you try to mess with these as they are there for generally good reasons:

<!-- for IIS6 -->
<httpHandlers>
  <add path="*" verb="*"
      type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

<!-- for IIS7 -->
<handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
Erv Walter
Thanks, Erv. I wasn't aware of this.
Nick DeVore