You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
805 B

  1. using System;
  2. namespace Apewer.Web
  3. {
  4. /// <summary>请求资源的 URL 已永久更改。在响应中给出了新的 URL。</summary>
  5. public sealed class RedirectResult : HeadResult
  6. {
  7. /// <summary>新的 URL。</summary>
  8. public string Location { get; private set; }
  9. /// <summary>重定向结果。</summary>
  10. /// <exception cref="ArgumentNullException" />
  11. public RedirectResult(string location) : base(302)
  12. {
  13. if (location.IsEmpty()) throw new ArgumentNullException(nameof(location));
  14. Headers.Add("Location", location);
  15. }
  16. /// <summary>执行。</summary>
  17. public override void ExecuteResult(ApiContext context)
  18. {
  19. context.Provider.SetRedirect(Location);
  20. }
  21. }
  22. }