1 changed files with 29 additions and 0 deletions
@ -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…
Reference in new issue