0
我想在MVC中使用区域。如果登录成功,您将被重定向到的HomeController
,并在Admin
区域中。我想要做的是将您重定向到默认区域的HomeController
的Index
,但是当我注销时,我留在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" }
);
}
}
嘿,你的项目好运气!你有没有针对我们的具体问题或...? – GrumpyCrouton
@GrumpyCrouton你是什么意思?我认为从文中可以明显看出,但是我已经添加了我的问题。 –