How to remove returnurl from url?

前端 未结 10 673
梦谈多话
梦谈多话 2020-11-28 08:54

I want to remove \"returnurl=/blabla\" from address bar when a user want to access to a login required page. Because I\'m trying to redirect the user to a static page after

10条回答
  •  Happy的楠姐
    2020-11-28 09:03

    Create a custom Authorize Attribute

    public class CustomAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(
                            AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
    
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                string loginUrl = "/"; // Default Login Url 
                filterContext.Result = new RedirectResult(loginUrl);
            }
        }
    }
    

    then use it on your controller

    [CustomAuthorizeAttribute]
    public ActionResult Login()
    {
    
    
        return View();
    }
    

提交回复
热议问题