Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Harshit 64 posts 226 karma points
    Feb 22, 2016 @ 10:21
    Harshit
    0

    Log out acton is not working

    Hi ,

    I am trying to implement logout, below is the code:

      public ActionResult MvcMemberLogout()
        {
            // clear the session 
            HttpContext.Session["redirectURL"] = null;
            Session.Clear();
            FormsAuthentication.SignOut();
            return Redirect("/");
        }
    

    calling from :

    <p>@Html.ActionLink("Log out", "MvcMemberLogout", " Membership")</p>
    

    however is not working. any idea about this?

  • Greg Fyans 140 posts 342 karma points
    Feb 22, 2016 @ 10:37
    Greg Fyans
    101

    You'll need to create a custom route otherwise Umbraco will intercept the request. Try adding this to your solution:

    using System;
    using System.Configuration;
    using System.Web.Routing;
    using Umbraco.Web;
    using Umbraco.Web.Mvc;
    
    namespace MyNamespace
    {
        public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.MapUmbracoRoute(
                    "logOut",
                    "LogOut",
                    new
                    {
                        controller = "Membership",
                        action = "MvcMemberLogout"
                    },
                    new UmbracoVirtualNodeByIdRouteHandler(1050); // set this to an actual node ID e.g. your homepage
            }
        }
    }
    

    Then you should be able to hit /logout.

    Remember to call RouteConfig.RegisterRoutes:

    public class Startup : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            base.ApplicationStarted(umbracoApplication, applicationContext);
    
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
    

    There's documentation on custom routes here:

    https://our.umbraco.org/documentation/reference/routing/custom-routes

  • Harshit 64 posts 226 karma points
    Feb 23, 2016 @ 11:02
    Harshit
    0

    thanks a lot gfyans :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies