Reputation: 164
ok for anyone else experiencing this in future it was a permissions issue with iis i had to set permissions on the whole tree for the style sheet to render
How do I attach a stylesheet? I've tried the usual way:
<LINK REL=StyleSheet HREF="../../Content/Site.css" TYPE="text/css" MEDIA=screen>
with various file paths. I've also tried with vb url.content scripts. For some reason nothing I try is displayed in the browser.
I get various results:
What else could be the problem?
Its attached to the master file, so i dont know what else is wrong here.
Upvotes: 1
Views: 1595
Reputation: 15253
"You can also drag the file from Solution Explorer to the head element of the page in Source view, or drag the file from Solution Explorer and drop it anywhere on the page in Design view."
http://msdn.microsoft.com/en-us/library/bb398932.aspx
UPDATE:
Check this post: http://forums.asp.net/p/1469427/3399574.aspx
The syntax provided by Robert should work.
Upvotes: 1
Reputation: 26956
What you need to remember with an MVC application is that often your URL's will not match up with your actual file system.
Assuming that you have a folder structure set up similar to the defaults:
/Content/
/Content/Site.css
/Views/
/Views/Home/
/Views/Home/index.aspx
/Views/Shared/
/Views/Shared/site.master
When you add the style declaration to your master page, your relative path makes sense:
../../Content/Site.css
Go two folders up from where I am now, and then down into
/content
to findSite.css
.
However, when you're viewing the page in your browser, that relative path is no longer valid:
Where's two folders down from this? Worse still, a deep link:
http://www.example.com/blogs/2010/11/23/My-posting
This will try and look for a folder called Content in the /blogs/2010/ folder.
You have two options:
href="/Content/Site.css"
this will tell the browser to always start from the root of your site.href="~/Content/Site.css"
- which, if the link is in a control that is set to runat="server"
should be corrected at runtime to point to the application root.Responding to comment
Ok, but we're getting somewhere now:
Looking at the URL you posted, on your development machine you're running this site as an application under the root? So when you request the site, you're going to: http://localhost/pulse/ ?
So what do you see in your browser if you request http://localhost/pulse/Content/Site.css ?
What does the Routes collection look like in your Global.asax.cs file? Is there something in there that is interfering with the /Content/ folder?
Upvotes: 3
Reputation: 105019
This is Asp.net MVC. Don't use relative file paths because paths are mostly related to routes. Use Url.Content()
helper instead.
<link rel="StyleSheet"
href="<%= Url.Content("~/Content/Site.css") %>"
type="text/css"
media="screen" />
Upvotes: 2