Browse Source

增加 RedirectResult

master
王厅 3 weeks ago
parent
commit
4912be1703
  1. 29
      Apewer/Web/RedirectResult.cs

29
Apewer/Web/RedirectResult.cs

@ -0,0 +1,29 @@
using System;
namespace Apewer.Web
{
/// <summary>请求资源的 URL 已永久更改。在响应中给出了新的 URL。</summary>
public sealed class RedirectResult : HeadResult
{
/// <summary>新的 URL。</summary>
public string Location { get; private set; }
/// <summary>重定向结果。</summary>
/// <exception cref="ArgumentNullException" />
public RedirectResult(string location) : base(302)
{
if (location.IsEmpty()) throw new ArgumentNullException(nameof(location));
Headers.Add("Location", location);
}
/// <summary>执行。</summary>
public override void ExecuteResult(ApiContext context)
{
context.Provider.SetRedirect(Location);
}
}
}
Loading…
Cancel
Save