public override Task RedirectToLogin(CookieRedirectContext context)
        {
            RouteData route = context.HttpContext.GetRouteData();
            ActionContext action = new ActionContext(context.HttpContext, route, new ActionDescriptor());
            context.RedirectUri = new UrlHelper(action).Action("Login", "Auth", new { area = "", returnUrl = context.Request.Path });

            return base.RedirectToLogin(context);
        }
        protected override async Task <bool> HandleForbiddenAsync(ChallengeContext context)
        {
            var properties = new AuthenticationProperties(context.Properties);
            var returnUrl  = properties.RedirectUri;

            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = OriginalPathBase + Request.Path + Request.QueryString;
            }
            var accessDeniedUri = Options.AccessDeniedPath + QueryString.Create(Options.ReturnUrlParameter, returnUrl);
            var redirectContext = new CookieRedirectContext(Context, Options, BuildRedirectUri(accessDeniedUri), properties);
            await Options.Events.RedirectToAccessDenied(redirectContext);

            return(true);
        }
 private async Task ApplyHeaders(bool shouldRedirectToReturnUrl, AuthenticationProperties properties)
 {
     Response.Headers[HeaderNames.CacheControl] = HeaderValueNoCache;
     Response.Headers[HeaderNames.Pragma]       = HeaderValueNoCache;
     Response.Headers[HeaderNames.Expires]      = HeaderValueMinusOne;
     if (shouldRedirectToReturnUrl && Response.StatusCode == 200)
     {
         var query       = Request.Query;
         var redirectUri = query[Options.ReturnUrlParameter];
         if (!StringValues.IsNullOrEmpty(redirectUri) &&
             IsHostRelative(redirectUri))
         {
             var redirectContext = new CookieRedirectContext(Context, Options, redirectUri, properties);
             await Options.Events.RedirectToReturnUrl(redirectContext);
         }
     }
 }
        protected override async Task <bool> HandleUnauthorizedAsync(ChallengeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var properties  = new AuthenticationProperties(context.Properties);
            var redirectUri = properties.RedirectUri;

            if (string.IsNullOrEmpty(redirectUri))
            {
                redirectUri = OriginalPathBase + Request.Path + Request.QueryString;
            }

            var loginUri        = Options.LoginPath + QueryString.Create(Options.ReturnUrlParameter, redirectUri);
            var redirectContext = new CookieRedirectContext(Context, Options, BuildRedirectUri(loginUri), properties);
            await Options.Events.RedirectToLogin(redirectContext);

            return(true);
        }
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToAccessDenied(CookieRedirectContext context) => OnRedirectToAccessDenied(context);
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToReturnUrl(CookieRedirectContext context) => OnRedirectToReturnUrl(context);
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToLogin(CookieRedirectContext context) => OnRedirectToLogin(context);
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToAccessDenied(CookieRedirectContext context) => OnRedirectToAccessDenied(context);
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToReturnUrl(CookieRedirectContext context) => OnRedirectToReturnUrl(context);
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event</param>
 public virtual Task RedirectToLogin(CookieRedirectContext context) => OnRedirectToLogin(context);