/// <summary> /// Called when authorization is required. /// </summary> /// <param name="filterContext">The filter context.</param> public void OnAuthorization(AuthorizationContext filterContext) { /* * var principal = filterContext.HttpContext.User; * HttpSessionState Session = HttpContext.Current.Session; * * TUserInfo user = default(TUserInfo); * user = PrepareUserInfo(principal, Session); * filterContext.HttpContext.User = (IPrincipal)user;*/ TUserInfo user = (TUserInfo)AUserInfo <TUserProperties> .GetCurrentUserInfo(); RolesRedirectURL roleRedirect; RolesRedirectAction action = CheckAuthorize(user, out roleRedirect, IsAllowAnonymous, DisableRedirectRoles, filterContext); switch (action) { case RolesRedirectAction.Unauthorized: HandleUnauthorizedRequest(filterContext); break; case RolesRedirectAction.Redirect: filterContext.Result = new RedirectResult(roleRedirect.Url + "?urlReturn=" + filterContext.HttpContext.Request.RawUrl); break; default: break; } }
public Task <HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation) { /* * var principal = actionContext.RequestContext.Principal; * HttpSessionState Session = HttpContext.Current.Session; * * TUserInfo user = default(TUserInfo); * user = PrepareUserInfo(principal, Session); * actionContext.RequestContext.Principal = (IPrincipal) user;*/ TUserInfo user = (TUserInfo)AUserInfo <TUserProperties> .GetCurrentUserInfo(); RolesRedirectURL roleRedirect; RolesRedirectAction action = CheckAuthorize(user, out roleRedirect, IsAllowAnonymous, DisableRedirectRoles, actionContext); switch (action) { case RolesRedirectAction.Unauthorized: throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)); case RolesRedirectAction.Redirect: throw new HttpResponseException(roleRedirect.HttpResponseMessage); default: return(continuation()); } }