public override async System.Threading.Tasks.Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext, System.Threading.CancellationToken cancellationToken) { var env = actionExecutedContext.ActionContext.Request.GetOwinEnvironment(); var scope = env.GetLifetimeScope(); var options = (IdentityServerOptions)scope.ResolveOptional(typeof(IdentityServerOptions)); var viewSvc = (IViewService)scope.ResolveOptional(typeof(IViewService)); var errorModel = new ErrorViewModel { SiteName = options.SiteName, SiteUrl = env.GetIdentityServerBaseUrl() }; var errorResult = new ErrorActionResult(viewSvc, env, errorModel); actionExecutedContext.Response = await errorResult.GetResponseMessage(); }
IHttpActionResult AuthorizeError(AuthorizeError error) { if (error.ErrorType == ErrorTypes.User) { var env = Request.GetOwinEnvironment(); var errorModel = new ErrorViewModel { SiteName = _options.SiteName, SiteUrl = env.GetIdentityServerBaseUrl(), CurrentUser = User.GetName(), ErrorMessage = error.Error }; var errorResult = new ErrorActionResult(_viewService, env, errorModel); return errorResult; } else { string character; if (error.ResponseMode == Constants.ResponseModes.Query || error.ResponseMode == Constants.ResponseModes.FormPost) { character = "?"; } else { character = "#"; } var url = string.Format("{0}{1}error={2}", error.ErrorUri.AbsoluteUri, character, error.Error); if (error.State.IsPresent()) { url = string.Format("{0}&state={1}", url, error.State); } Logger.Info("Redirecting to: " + url); return Redirect(url); } }