RequestCookie.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Web;
  3. namespace OSHttpServer
  4. {
  5. /// <summary>
  6. /// cookie sent by the client/browser
  7. /// </summary>
  8. /// <seealso cref="ResponseCookie"/>
  9. public class RequestCookie
  10. {
  11. private readonly string _name = null;
  12. private string _value = null;
  13. /// <summary>
  14. /// Constructor.
  15. /// </summary>
  16. /// <param name="id">cookie identifier</param>
  17. /// <param name="content">cookie content</param>
  18. /// <exception cref="ArgumentNullException">id or content is null</exception>
  19. /// <exception cref="ArgumentException">id is empty</exception>
  20. public RequestCookie(string id, string content)
  21. {
  22. if (string.IsNullOrEmpty(id)) throw new ArgumentNullException("id");
  23. if (content == null) throw new ArgumentNullException("content");
  24. _name = id;
  25. _value = content;
  26. }
  27. #region inherited methods
  28. /// <summary>
  29. /// Gets the cookie HTML representation.
  30. /// </summary>
  31. /// <returns>cookie string</returns>
  32. public override string ToString()
  33. {
  34. return string.Format("{0}={1}; ", HttpUtility.UrlEncode(_name), HttpUtility.UrlEncode(_value));
  35. }
  36. #endregion
  37. #region public properties
  38. /// <summary>
  39. /// Gets the cookie identifier.
  40. /// </summary>
  41. public string Name
  42. {
  43. get { return _name; }
  44. }
  45. /// <summary>
  46. /// Cookie value. Set to null to remove cookie.
  47. /// </summary>
  48. public string Value
  49. {
  50. get { return _value; }
  51. set
  52. {
  53. _value = value;
  54. }
  55. }
  56. #endregion
  57. }
  58. }