简体   繁体   中英

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. 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 >

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM