NopCommerce:将/admin管理路由改为/adminarea并忽略原路由的问题
Solution to Change NopCommerce Admin Route to /adminarea & Ignore /admin
Got it, let's walk through how to update your NopCommerce admin route and block the old /admin path—this is straightforward once you know where to look (since the admin routes aren't in the main RouteProvider.cs like you initially checked).
Step 1: Update the Admin Area Route Prefix
NopCommerce uses ASP.NET MVC Areas for the admin section, so the core admin route is defined in the Admin area's registration file:
- Open
Nop.Web/Areas/Admin/AdminAreaRegistration.cs - Locate the
RegisterAreamethod, which contains the admin route mapping. It’ll look something like this:
public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new[] { "Nop.Web.Areas.Admin.Controllers" } ); }
- Modify the route URL string from
"admin/{controller}/{action}/{id}"to"adminarea/{controller}/{action}/{id}" - Save the file.
Step 2: Ignore the Old /admin Route
Next, we’ll ensure any requests to the old /admin path are ignored. Add this rule to the main route provider:
- Open
Nop.Web/Infrastructure/RouteProvider.cs - In the
RegisterRoutesmethod, add the ignore rule before any other route mappings (route matching is order-dependent):
public void RegisterRoutes(RouteCollection routes) { // Add this line first to block all /admin requests routes.IgnoreRoute("admin/{*pathInfo}"); // Existing route logic below routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // ... rest of your route code }
The {*pathInfo} wildcard ensures all subpaths under /admin (like /admin/login or /admin/dashboard) are also ignored.
Step 3: Verify & Test
- Restart your NopCommerce application to apply the route changes.
- Navigate to
yourdomain.com/adminarea—you should land on the admin login page as normal. - Try accessing
yourdomain.com/admin—it should return a 404 error, as the route no longer resolves to admin pages.
Quick Notes to Avoid Issues
- Third-Party Plugins: A small number of plugins might hardcode
/adminin links instead of using MVC’s route helpers. If you spot broken plugin links, check their code for direct URL references and update them to useUrl.ActionorHtml.ActionLinkwith the admin area specified. - Cache Clearing: Clear NopCommerce’s static cache (either via the admin settings or by deleting the
App_Data/Tempfolder) to ensure cached route data is refreshed.
内容的提问来源于stack exchange,提问作者Mina Sameh
相关产品推荐
相关产品推荐

