Seamlessly Port MVC5 Bundles to ASP.NET Core While Preserving URLs

Neptune Infotech Team
Neptune Infotech Team
|
December 01, 2026
Seamlessly Port MVC5 Bundles to ASP.NET Core While Preserving URLs

Many enterprises still run critical business portals on ASP.NET MVC 5, relying on System.Web.Optimization for bundling CSS and JavaScript. As .NET moves forward, migrating to ASP.NET Core is essential for performance, security, and long‑term support.

Bundle migration refers to the process of moving System.Web.Optimization bundles from an ASP.NET MVC5 application to ASP.NET Core while keeping the original virtual paths unchanged.

Why Keep the Same URLs?

Changing bundle URLs can break cached resources, SEO tags, and third‑party integrations that reference the exact virtual path. Preserving the original ~/bundles/* and ~/Content/* routes eliminates the need for a massive rewrite of view files and avoids 404 errors after deployment.

Step‑by‑Step Guide to Preserve Bundle Paths

  1. Add the Microsoft.AspNetCore.StaticFiles package to enable serving static files from custom folders.
  2. Create a wwwroot folder structure that mirrors the old MVC5 layout (e.g., wwwroot/bundles and wwwroot/Content).
  3. Copy the compiled bundle files (e.g., jquery-3.6.0.min.js, bootstrap.css) into the corresponding folders.
  4. Register a StaticFileOptions middleware in Startup.cs that maps the legacy virtual paths to the new physical locations:

app.UseStaticFiles(new StaticFileOptions { RequestPath = "/bundles", FileProvider = new PhysicalFileProvider(Path.Combine(env.WebRootPath, "bundles")) });

app.UseStaticFiles(new StaticFileOptions { RequestPath = "/Content", FileProvider = new PhysicalFileProvider(Path.Combine(env.WebRootPath, "Content")) });

These calls ensure that requests to /bundles/jquery or /Content/css are served from the new wwwroot location without altering view code.

Configuring ASP.NET Core to Serve Legacy Bundle URLs

  • Replace @Scripts.Render("~/bundles/jquery") and @Styles.Render("~/Content/css") with standard