简体   繁体   中英

ASP.net MVC bundles https

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM