Asp.net mvc 4 Can';t删除控制器名称MVC4
我正在Asp.net mvc 4 Can';t删除控制器名称MVC4,asp.net-mvc-4,redirect,asp.net-mvc-routing,Asp.net Mvc 4,Redirect,Asp.net Mvc Routing,我正在MVC4中工作,在那里我需要将特定场景下的用户重定向到LogOut。我正在使用.js文件中的重定向。但是当我尝试重定向路由时是不正确的。它将添加到现有的控制器并抛出错误 //代码 //.cshtml: <script type="text/javascript"> var logoutUrl = '@Url.Action("LogOut", "Account")'; </script> //.JS: window.location.href = log
MVC4
中工作,在那里我需要将特定场景下的用户重定向到LogOut
。我正在使用.js
文件中的重定向。但是当我尝试重定向路由时
是不正确的。它将添加到现有的控制器
并抛出错误
//代码
//.cshtml:
<script type="text/javascript">
var logoutUrl = '@Url.Action("LogOut", "Account")';
</script>
//.JS:
window.location.href = logoutUrl;
当我尝试重定向时,用户将在页面中
/Home/Index
但是,在重定向之后,它将转到
/Home/Account/LogOut
而不是/Account/LogOut
我的路线图
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 }
);
}
这让我犯了个错误。但是我需要从url中删除主页
,并重定向到帐户/注销
如何实现这一点?请确保您获得了正确的url,或者出于测试目的,只需使用硬编码url即可 再试一次
var logoutUrl='/Account/LogOut'代码>
PS:如果可以的话,我会发表评论的,但是我的声誉会降低
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 }
);
}