2017-02-26 19 views
0

我已經改變了默認路由配置到另一個控制器和動作像下面如何重定向註銷並登錄到另一個CONTROLER和行動

routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new string[] { "WebStore.Controllers" } 
     ); 

前:

controller:Home 
action:Index 

現在:

controller:Products 
    action:Index 

現在登錄和註銷後,它又回到(家/索引),而我想要它去

Products/Index 
+0

你需要從的AccountController 改變你有2個功能註銷等( )和登錄 – liran

+0

請提供更多代碼示例。 –

回答

0

您必須告訴您的登錄和註銷操作接下來要去哪裏。

你可以簡單地做:

public ActionResult login(string username, string password) 
{ 
// your login code 
return Redirect("/"); 
} 

public ActionResult logoff() 
{ 
// your log off code 
return Redirect("/"); 
} 

,或者如果您使用的子域,你可以告訴它重定向到具體路線:

return RedirectToRoute("Default", new { controller = "", action = "" }); 
相關問題