2017-08-07 47 views
0

我想在MVC中使用区域。如果登录成功,您将被重定向到的HomeController,并在Admin区域中。我想要做的是将您重定向到默认区域的HomeControllerIndex,但是当我注销时,我留在Admin区域。如何重定向回管理区域?MVC没有区域的默认根目录

登录内部NAV

 <ul class="nav masthead-nav"> 
      <li class="active"><a href="@Url.Action("Index", "Home")">Domů</a></li> 
      <li><a href="@Url.Action("About", "Home")">O nás</a></li> 
      <li><a href="@Url.Action("Index", "Login", new {area = "Admin" })">Vypis lyží/snowboardů</a></li> 
    </ul> 

登录控制器动作注册/ Signout

public ActionResult SignIn(string login, string password) 
     { 
      if (Membership.ValidateUser(login, password)) 
      { 
       FormsAuthentication.SetAuthCookie(login, false); 
       return RedirectToAction("Index", "Home"); 
      } 

      TempData["error"] = "Login nebo heslo není správné"; 
      return RedirectToAction("Index", "Login"); 
     } 

     public ActionResult Logout() 
     { 
      FormsAuthentication.SignOut(); 
      Session.Clear(); 

      return RedirectToAction("Index", "Home"); 
     } 

路由配置

public class 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 }, 
       namespaces: new [] { "pujcovna_lyze.Controllers" } 
      ); 
     } 
    } 
+0

嘿,你的项目好运气!你有没有针对我们的具体问题或...? – GrumpyCrouton

+0

@GrumpyCrouton你是什么意思?我认为从文中可以明显看出,但是我已经添加了我的问题。 –

回答

2

我已通过在Logout()操作中添加new { area = "" }参数解决了该问题。

行动,现在看起来是这样的:

public ActionResult Logout() 
     { 
      FormsAuthentication.SignOut(); 
      Session.Clear(); 

      return RedirectToAction("Index", "Home", new { area = "" }); 
     }