diff --git a/Apewer/Web/RedirectResult.cs b/Apewer/Web/RedirectResult.cs new file mode 100644 index 0000000..96cd00a --- /dev/null +++ b/Apewer/Web/RedirectResult.cs @@ -0,0 +1,29 @@ +using System; + +namespace Apewer.Web +{ + + /// 请求资源的 URL 已永久更改。在响应中给出了新的 URL。 + public sealed class RedirectResult : HeadResult + { + + /// 新的 URL。 + public string Location { get; private set; } + + /// 重定向结果。 + /// + public RedirectResult(string location) : base(302) + { + if (location.IsEmpty()) throw new ArgumentNullException(nameof(location)); + Headers.Add("Location", location); + } + + /// 执行。 + public override void ExecuteResult(ApiContext context) + { + context.Provider.SetRedirect(Location); + } + + } + +}