Why is resource redirection redirected in my ASP MVC4 application?

I am using RC, and I have verified that everything is updated through NuGet. In my global.asax.cs file appeared:

BundleTable.Bundles.AddDefaultFileExtensionReplacements(); BundleTable.Bundles.AddDefaultIgnorePatterns(); BundleTable.Bundles.AddDefaultFileOrderings(); Bundle scripts = new Bundle("~/Scripts"); scripts.IncludeDirectory("~/Scripts", "*.js"); BundleTable.Bundles.Add(scripts); Bundle css = new Bundle("~/Content/css"); css.IncludeDirectory("~/Content/css", "*.css", false); BundleTable.Bundles.Add(css); 

I tried several different configurations of this without any improvements.

Then in my layout ive got:

 <link href="@BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" /> <script src="@BundleTable.Bundles.ResolveBundleUrl("~/Scripts")"> </script> 

When the page loads decent decent URLs:

 <link href="/Content/css?v=QAsFYXHCbnaU70oGVxpgi9py9iKQrT9C4BVNdHa7xoI1" rel="stylesheet" type="text/css" /> 

But this URL redirects to:

 /Content/css/ 

What returns 404 not found error ...

bundle redirection ...

Does anyone have any ideas?

+6
source share
2 answers

The logic of the bundle module, which decides whether or not to process the request, will not accept requests for existing files or directories. Therefore, why your package requests do not work when they live on the same virtual path as the existing directory (or file).

+4
source

The scripts ~ / Scripts and ~ / Content / css already exist on the disk, so you need to make it some virtual url, say ~ / Scripts / js and ~ / Content / styles, that it is good now.

 Bundle scripts = new Bundle("~/Scripts/js"); scripts.IncludeDirectory("~/Scripts", "*.js"); BundleTable.Bundles.Add(scripts); Bundle css = new Bundle("~/Content/styles"); css.IncludeDirectory("~/Content/css", "*.css", false); BundleTable.Bundles.Add(css); 

Also in MVC4, the routing, bundle, and filter configuration has been moved to

~ / App_Start / (RouteConfig, BundleConfig, FilterConfig) .cs

so check that you have these, if so, then write your configurations there.

+6
source

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


All Articles