UnauthorizedException.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Net;
  3. namespace OSHttpServer.Exceptions
  4. {
  5. /// <summary>
  6. /// The request requires user authentication. The response MUST include a
  7. /// WWW-Authenticate header field (section 14.47) containing a challenge
  8. /// applicable to the requested resource.
  9. ///
  10. /// The client MAY repeat the request with a suitable Authorization header
  11. /// field (section 14.8). If the request already included Authorization
  12. /// credentials, then the 401 response indicates that authorization has been
  13. /// refused for those credentials. If the 401 response contains the same challenge
  14. /// as the prior response, and the user agent has already attempted authentication
  15. /// at least once, then the user SHOULD be presented the entity that was given in the response,
  16. /// since that entity might include relevant diagnostic information.
  17. ///
  18. /// HTTP access authentication is explained in rfc2617:
  19. /// http://www.ietf.org/rfc/rfc2617.txt
  20. ///
  21. /// (description is taken from
  22. /// http://www.submissionchamber.com/help-guides/error-codes.php#sec10.4.2)
  23. /// </summary>
  24. public class UnauthorizedException : HttpException
  25. {
  26. /// <summary>
  27. /// Create a new unauhtorized exception.
  28. /// </summary>
  29. /// <seealso cref="UnauthorizedException"/>
  30. public UnauthorizedException()
  31. : base(HttpStatusCode.Unauthorized, "The request requires user authentication.")
  32. {
  33. }
  34. /// <summary>
  35. /// Create a new unauhtorized exception.
  36. /// </summary>
  37. /// <param name="message">reason to why the request was unauthorized.</param>
  38. /// <param name="inner">inner exception</param>
  39. public UnauthorizedException(string message, Exception inner)
  40. : base(HttpStatusCode.Unauthorized, message, inner)
  41. {
  42. }
  43. /// <summary>
  44. /// Create a new unauhtorized exception.
  45. /// </summary>
  46. /// <param name="message">reason to why the request was unauthorized.</param>
  47. public UnauthorizedException(string message)
  48. : base(HttpStatusCode.Unauthorized, message)
  49. {
  50. }
  51. }
  52. }