public override void OnException(ExceptionContext context) { base.OnException(context); switch (context.Exception.GetType().Name) { case nameof(NotAiurSignedInException): { var exp = context.Exception as NotAiurSignedInException; var r = context.HttpContext.Request; string ServerPosition = $"{r.Scheme}://{r.Host}"; string url = UrlConverter.UrlWithAuth(ServerPosition, exp.SignInRedirectPath); context.ExceptionHandled = true; context.HttpContext.Response.Redirect(url.ToString()); } break; case nameof(AiurUnexceptedResponse): { var exp = context.Exception as AiurUnexceptedResponse; var arg = new AiurProtocal { code = exp.Response.code, message = exp.Response.message }; var url = new AiurUrl(string.Empty, "api", "exception", arg); context.ExceptionHandled = true; context.HttpContext.Response.Redirect(url.ToString()); } break; case nameof(ModelStateNotValidException): { var exp = context.Exception as ModelStateNotValidException; var arg = new AiurProtocal { code = ErrorType.InvalidInput, message = "Input not valid!" }; var url = new AiurUrl(string.Empty, "api", "exception", arg); context.ExceptionHandled = true; context.HttpContext.Response.Redirect(url.ToString()); } break; default: { var exp = context.Exception as Exception; var arg = new AiurProtocal { code = ErrorType.UnknownError, message = exp.Message }; var url = new AiurUrl(string.Empty, "api", "exception", arg); context.ExceptionHandled = true; context.HttpContext.Response.Redirect(url.ToString()); } break; } }
private RedirectResult _Redirect(ActionExecutingContext context, string page, bool?justTry, bool register) { var r = context.HttpContext.Request; string serverPosition = $"{r.Scheme}://{r.Host}"; string url = UrlConverter.UrlWithAuth(serverPosition, page, justTry, register); return(new RedirectResult(url)); }