private static void SetUnauthorized(ActionExecutingContext actionContext)
        {
            CurrentSessionHandler session = new CurrentSessionHandler(HttpContext.Current.Session);

            session.Reset();

            RouteValueDictionary loginRoute = new RouteValueDictionary
            {
                { "controller", "Account" },
                { "action", "Login" }
            };

            actionContext.Result = new RedirectToRouteResult(loginRoute);
        }
Example #2
0
        private static void SetInternalServerError(HttpActionContext actionContext)
        {
            try
            {
                CurrentSessionHandler session = new CurrentSessionHandler(HttpContext.Current.Session);
                session.Reset();
            }
            catch (Exception)
            {
                // Try to reset session, but could have been cause of this method call, so have to carry on.
            }

            actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.InternalServerError);
        }
Example #3
0
        private static void SetUnauthorizedRedirect(HttpActionContext actionContext, String reasonPhrase)
        {
            CurrentSessionHandler session = new CurrentSessionHandler(HttpContext.Current.Session);

            session.Reset();

            HttpResponseMessage response = actionContext.Request.CreateResponse(HttpStatusCode.Redirect);

            response.ReasonPhrase = reasonPhrase;

            Uri redirectUri = new Uri(UrlHelper.GetLoginRedirectUrl());

            response.Headers.Location = redirectUri;
            actionContext.Response    = response;
        }
        public IHttpActionResult Logout()
        {
            try
            {
                CurrentSessionHandler session = new CurrentSessionHandler(HttpContext.Current.Session);
                session.Reset();

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error attempting to log out user.");
                return(InternalServerError());
            }
        }
        private void SetUnauthorized(HttpActionContext actionContext, CurrentSessionHandler session)
        {
            session.Reset();

            actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
        }