-1
我在MVC4
工作,我需要在特定场景下将用户重定向到LogOut
。我正在使用.js
文件中的重定向。但是,当我尝试重定向routing
是不正确的。它增加了现有的controller
,并把我错误。无法删除控制器名称MVC4
//代码
// .cshtml:
<script type="text/javascript">
var logoutUrl = '@Url.Action("LogOut", "Account")';
</script>
//控制器:
[AllowAnonymous]
public ActionResult LogOut()
{
FormsAuthentication.SignOut();
return RedirectToAction("Login", "Account", null);
}
//.JS:
window.location.href = logoutUrl;
当我尝试重定向用户将在页面
/Home/Index
但是,重定向后它去
/Home/Account/LogOut
,而不是/Account/LogOut
我routeConfig,
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}
,这将引发我的错误。但我需要从网址中删除Home
并重定向到Account/LogOut
。
我该如何做到这一点?