How to stop Kentico from adding stylesheet link to end of <head>?

Bryan Drenner asked on October 8, 2014 23:23

My company's marketing department just noticed some style glitches on our site, and it's coming from a tag that Kentico 8 is automatically adding to <head>:

<link href="/CMSPages/GetResource.ashx?stylesheetfile=/App_Themes/OurTheme/style.css" type="text/css" rel="stylesheet" />

This element is not in our master template because *gasp* we don't want it there. How can I stop Kentico from rendering it?

Correct Answer

Yehuda Lando answered on October 9, 2014 18:14

It happens because OurTheme is a theme.

When you have a theme set up, ASP.NET will register all .css files in the header.

What you have to do is move this css to a different folder.

Also, if you use a .less file as your style sheet, this will not happen.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Charles Matvchuk answered on October 9, 2014 00:28

What is assigned to your site as a Style Sheet under Sites?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 9, 2014 13:33

Kentico is not doing that, IIS is. You must have that "style.css" file in the physical file system. By default IIS automatically adds all .css files into the HEAD tag. My suggestion is to take the css in that stylesheet and put it into the CSS Stylesheets module and then use the HEAD HTML or CSS Stylesheet webpart(s) and place it on your master page template or other template you desire. This way you have full control over it.

1 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on October 9, 2014 16:33

Charles, the site has been assigned the "OurTheme" stylesheet. It seems that if a site is assigned a stylesheet called "MyStyle", Kentico renders out GetResource.ashx links to every CSS file it finds under /App_Themes/MyStyle. I can't find a straightforward way to disable this behavior.

Brenden, I must have misunderstood you. Yes, "style.css" is in the file system, but I've never seen IIS or ASP.NET behave in the manner you describe. Also, the unwanted <link> tag's URL is being set specifically to Kentico's GetResources handler.

0 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on October 9, 2014 18:29

Brenden and Yehuda, it looks like ASP.NET Themes do indeed add these links to the <head>. Wow, I'm humbled.

Now I'm curious: How does ASP.NET know to render the <link> elements to use Kentico's GetResources handler?

It looks like I'll have to move my CSS files to CMSGlobalFiles.

0 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on October 9, 2014 22:27

I ended up solving this pretty easily: In the Sites app, I changed the site stylesheet to "(None)".

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 10, 2014 15:18

@Bryan "In the Sites app, I changed the site stylesheet to '(None)'"

I do this more and more now using 3rd party tools like Bootstrap or Foundation for layouts. This allows me to use the HEAD HTML or CSS Webparts to place the stylesheets in the order I want on the master page. The ONLY time I store .css in the file system is during development as it's easier to edit the stylesheet in Visual Studio than the editor.

1 votesVote for this answer Mark as a Correct answer

Bryan Drenner answered on October 10, 2014 17:28

@Brenden, that's a great idea. Thanks for the tip!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.