RedirectToAction直接指向默认控制器操作

时间:2016-05-04 14:43:58

标签: asp.net-mvc

我想从

更改登录重定向
return RedirectToAction("Index", "Home");

return RedirectToAction("Foo", "Profile");

Foo动作返回一个视图。 问题是我仍然得到了家/索引。

我是否需要更改路由?

RouteConfig是这样的:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

    routes.MapRoute(
        name: "NotFound",
        url: "{*catchall}",
        defaults: new { controller = "Home", action = "Index" }
    );

}

1 个答案:

答案 0 :(得分:0)

问题是登录后重定向重定向到根'/'url。 您可以通过路线重置此项。 如下所示:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Profile", action = "Foo", id = UrlParameter.Optional }
);

routes.MapRoute(
    name: "NotFound",
    url: "{*catchall}",
    defaults: new { controller = "Profile", action = "Foo" }
);

enter image description here