asp.net-mvc – MVC Response.RedirectToRoute(RouteData.Values)重定向到Area控制器

我使用RedirectToRoute方法强制在url中进行文化.一切正常,直到我在项目中创建一个Admin区域.现在该方法重定向到区域控制器.

主HomeController示例:/ Home / Contact

public ActionResult Contact()
    {
       Response.RedirectToRoute(RouteData.Values);
       return View();
    }

该方法重定向到/ Admin / Home / Contact,重定向前RouteData.Values的值为:

[0] "Controller"  Home
[1] " Action"     Contact

我的主要路线:

routes.MapRoute("Default_culture", "{culture}/{controller}/{action}/{id}",
                            new { controller = "Home", action = "Index",  id = UrlParameter.Optional , new { culture = "([a-z]{2,3})(-[a-zA-Z]{2})?" }, new[] { "Project.Controllers" });

routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "Project.Controllers" });

RegisterArea方法中的路由:

context.MapRoute(null, "{culture}/Admin/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { culture = "([a-z]{2,3})(-[a-zA-Z]{2})?" }, new[] { "Project.Areas.Admin.Controllers" });

context.MapRoute(null, "Admin/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "Project.Areas.Admin.Controllers" });

我不明白这种行为.我究竟做错了什么?

最佳答案 我刚刚在我的网站上解决了这个问题.

更改Response.RedirectToRoute(RouteData.Values);

至Response.RedirectToRoute(“Default”,RouteData.Values);

点赞