ASP.NET MVC 4 Bundles giving 404 error

I want to add Bundles to an existing ASP.NET MVC 4 website (.NET 4.5) that uses:

I tried following the instructions: https://gist.github.com/jkarsrud/5143239 , and the CSS loaded before I started the package path.

On loading the page, he inserts a link to the style:

<link href="/bundles/marketingcss" rel="stylesheet">

But error 404 occurs:

> GET http://localhost:20459/bundles/marketingcss 404 (Not Found) 

Here is what I have in the code:

Web.config

<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles" />

Global.asax

<%@ Application Codebehind="Global.asax.cs" Inherits="MapCom.Global" Language="C#" %>

Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Security;
using System.Web.SessionState;
using Umbraco.Web;

namespace MapCom
{
    public class Global : UmbracoApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            base.OnApplicationStarted(sender, e);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

_Layout.cshtml

@Styles.Render("~/bundles/marketingcss");

Bundleconfig.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;

namespace MapCom
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            BundleTable.EnableOptimizations = true;
            ///
            ///Marketing Site CSS Bundle
            ///
            bundles.Add(new StyleBundle("~/bundles/marketingcss")
                .Include("~/plugins/bootstrap/css/bootstrap.min.css")
                .Include("~/css/font-awesome.min.css")
                .Include("~/plugins/parallax-slider/css/parallax-slider.css")
                .Include("~/css/combinedStyles.min.css")
                .Include("~/plugins/ladda-buttons/css/ladda.min.css")
                .Include("~/plugins/ladda-buttons/css/custom-lada-btn.css"));
        }
    }
}

Any ideas?

+4
3

Umbraco , , , :

 public class ApplicationEventHandler : IApplicationEventHandler

: http://our.umbraco.org/documentation/Reference/Events/application-startup

:

Umbraco, . Umbraco, , . , , .

, Umbraco ASP.NET.

, System.Web.Optimization ApplicationEventHandler.cs :

public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}
+6

, , web.config

BundleTable.Bundles.Add(new ScriptBundle("~/opt/jscripts").Include(
                "~/Scripts/twitterFetcher.js"
                ));
            BundleTable.EnableOptimizations = true;

Umbraco

<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />

<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/opt/" />
+4

:

1. bundles css , - . :

 bundles.Add(new StyleBundle("~/Content/marketingcss")

(), , , marketingcss , - , )

2. _Layout.cshtml :

 @Styles.Render(BundleTable.Bundles.ResolveBundleUrl("~/Content/marketingcss"))

3. , _Layout.cshtml :

<link href="@System.Web.Optimization.BundleTable.
               Bundles.ResolveBundleUrl("~/Content/marketingcss")"
               rel="stylesheet"
               type="text/css" /> 

4. Just saw that one of our friends commented not to put .min files in your package, which is correct, therefore you should not include .min files in your budleConfig class and just use regular files, for example bootstarp.cssfrom bootstrap.min.cssand do the same for of all other files, of course, make sure you have normal files, so don't just change the names.

Hope this helps fix your code.

+2
source

Source: https://habr.com/ru/post/1543306/


All Articles