【发布时间】:2018-07-31 08:07:23
【问题描述】:
我希望你能帮助我:) 我正在尝试在我的 .net mvc 应用程序中执行注销功能,但我制作的链接永远不会到达正确的路线。这是我的代码:
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 }
);
}
public ActionResult LogOff()
{
Session[UserSessionIdentifier] = null;
return RedirectToAction("Index", "Home");
}
@Html.ActionLink("Log off", "LogOff", "Account")
当我点击这个链接时,我的浏览器中有这个网址:
http://localhost:52041/Account/Login?ReturnUrl=%2FAccount%2FLogOff
我的错误在哪里?
【问题讨论】:
-
您是否在控制器中激活了
AuthorizeAttribute?听起来你应该在销毁注销用户的会话数据后用[AllowAnonymous]标记LogOff操作。 -
好的,我的班级有一个 [Authorize] 属性,这就是为什么!在 LogOff 方法上允许 [AllowAnonymous] 有效,谢谢 :)
标签: c# model-view-controller routing