15

I'm having troubles with my style sheets bundling after deployment to IIS. I've created a simple solution to demonstrate my problem.

I've created a simple test project (VS 2012, MVC 4) with a single controller and a view containing an "Hello World" string.

I've created a (test) CSS under the content folder with simple simple color changing

Content\helloWorldCss\helloWorldStyle.css

Then, I've edited my BundleConfig.cs class and added the path to my CSS as a new bundle:

            bundles.Add(new StyleBundle("~/Content/helloWorldCss").Include("~/Content/helloWorldCss/helloWorldStyle.css"));

Then, I've added the new bundle to my the _Layout.cshtml:

@Styles.Render("~/Content/helloWorldCss")

When I run my application via VS (or Page inspector) my CSS is being applied successfully and everything seems to be OK. However, when I publish/deploy my project to IIS (through VS), I can view my HTML but my CSS is not being applied. The following file exists after deployment:

Content\helloWorldCss\helloWorldStyle.css

What really puzzles me is that when I alter my _Layout.cshtml and add a "regular" ref to the same CSS instead of using the bundle ref, the CSS is applied after publishing without any issues.

<link href="@Url.Content("~/Content/helloWorldCss/helloWorldStyle.css")" rel="stylesheet" type="text/css" />*

I will appreciate any help and advice on this.

Omri
  • 1,058
  • 3
  • 14
  • 26

3 Answers3

15

I think you've got a name collision here. ASP.NET MVC will create a file on http://example.org/Content/helloWorldCss after minification and you already have a folder with the same path. Can you try it again after renaming your bundle?

BundleConfig.cs:

bundles.Add(new StyleBundle("~/Content/helloWorld").Include("~/Content/helloWorldCss/helloWorldStyle.css"));

_Layout.cshtml:

@Styles.Render("~/Content/helloWorld")
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
  • the '~' sign here is the main source of confusion. The sign is required for defining the bundle. This made me think it must be the folder path which MUST NOT be. :) Thanks!! Helped me. – mrsrizan Oct 20 '14 at 09:08
7

This is what i do. IIS Config>Authentication>RightClickOn Anonymous Auth>Click Edit> Check Application pool identity

IIS Config>Authentication>RightClickOn Anonymous Auth>Click Edit> Check Application pool identity

shiroxx
  • 177
  • 1
  • 2
1

When you use VS publish to a test server, it uses defaultAppPool. For the styling and SimpleMembership to work you need:

  1. Install ASP.NET 4.0 on your server. cmd -- cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\ Type aspnet_regiis.exe -ir

  2. Add an ASP.NET 4.0 app pool in IIS.

  3. Set your site to use ASP.NET 4.0 as app pool.

  4. Add an ASP.NET 4.0 security login in SQL Server and give it dbcreate role.

Yini
  • 691
  • 8
  • 9