1
votes

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.

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 <link>? - user3559349
yes, it's only one custom.css is being loaded. not only @styles.Rneder" giving this error but also @Scripts.Render("~/bundles/jquery") - June
main page is https. However, the script and styles render as domain:443 instead of https. - June
can you find the solution? - Sepehr Estaki

1 Answers

0
votes

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.