1

asp.net mvc bundles do not render for https.

here is my code:

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

View

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

And the error code I get is:

Mixed Content: The page at 'https://domain/' was loaded over HTTPS, but requested an insecure stylesheet 'http://domain:443/Content/css/custom.css'. This request has been blocked; the content must be served over HTTPS.

June
  • 51
  • 6
  • 1
    When you use `@Styles.Render()` it uses the same HTTP scheme as the main page so the error is not making sense in relation to your bundle. Are you sure you do not have another copy of `custom.css` being loaded as a ``? –  May 04 '18 at 06:38
  • yes, it's only one custom.css is being loaded. not only @styles.Rneder" giving this error but also @Scripts.Render("~/bundles/jquery") – June May 04 '18 at 06:56
  • main page is https. However, the script and styles render as http://domain:443 instead of https. – June May 04 '18 at 07:00
  • can you find the solution? – Sepehr Estaki Dec 02 '18 at 14:18
  • https://stackoverflow.com/questions/44957666/asp-net-bundling-causing-https-error – Jorge Dominguez Sep 01 '20 at 18:48

2 Answers2

0

Do you have ~/Content/css/css as a real path in your app?

IIS is probably trying to handle the request.

Rename your bundle or the folder in your app and it should work.

So try this:

bundles.Add(new StyleBundle("~/Content/core.css").Include("~/Content/css/custom.css"));

Then in your view:

@Styles.Render("~/Content/core.css")

The style bundle name can be anything you want, it doesn't have to be related to the real location of your CSS file.

Update

If you are getting mixed content errors, that's because some of your content is coming over HTTPS and other content is coming over HTTP.

The best way to overcome this problem is use // on all your content.

So say for example you have an image like this

<img src="http://website.com/images/smiley.gif">

change it too

<img src="//website.com/images/smiley.gif">

That should stop your mixed content warnings.

Ayo Adesina
  • 2,231
  • 3
  • 37
  • 71
  • I am still getting the same error after changing to your suggestion. Mixed Content: The page at 'https://domain/' was loaded over HTTPS, but requested an insecure stylesheet 'http://domain:443/Content/css/custom.css'. This request has been blocked; the content must be served over HTTPS. – June May 04 '18 at 10:38
  • I do not have any web url in my page. In MVC View: @Styles.Render("~/Content/core.css") @Scripts.Render("~/bundles/jquery") In BundleConfig.cs bundles.Add(new StyleBundle("~/Content/core.css").Include("~/Content/css/custom.css")); bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Content/js/jquery-{version}.js")); – June May 07 '18 at 02:41
0

Use a different bundle folder

Like, Update

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

To

bundles.Add(new StyleBundle("~/CssBundles/css/css").Include("~/Content/css/custom.css"));

This issue happens if you use an existing project folder for the bundle location.

Shemeemsha R A
  • 1,416
  • 16
  • 22