[英]C# MVC 5 routing
I hope you can help me :) I'm trying to do a logoff function in my .net mvc app, but links that I make never reach le right route. 希望您能对我有所帮助:)我正在尝试在.net mvc应用程序中执行注销功能,但是我制作的链接始终无法到达正确的路径。 Here is my code :
这是我的代码:
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")
When I click on this link, I had this url in my browser : 当我单击此链接时,我的浏览器中有以下网址:
http://localhost:52041/Account/Login?ReturnUrl=%2FAccount%2FLogOff
Where is my error ? 我的错误在哪里?
In your logoff function you should clear any session variable. 在注销功能中,您应该清除所有会话变量。 Instead of @HTML.ActionLink() try to use < a href="/Account/LogOff" >Log Off< /a >
代替@ HTML.ActionLink()尝试使用<a href =“ / Account / LogOff”>注销</ a>
I'm not sure you saw it but my problem is solved, answer is in first post comments. 我不确定您是否看到了,但是我的问题已解决,答案在第一篇评论中。 Anyway, thanks for the tip about clear session variables :)
无论如何,感谢您提供有关清除会话变量的提示:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.