Partilhar via


Troubleshooting Exceptions: System.Net.CookieException 

A CookieException exception is thrown when an error is made adding a cookie to a cookie container.

Associated Tips

  • Make sure the cookie size does not exceed the maximum allowed by the cookie container.
    This exception is thrown when an attempt is made to add a Cookie with length greater than MaxCookieSize to a CookieContainer. The default maximum cookie size is 4096 bytes.
  • When setting the Name property for a cookie, make sure the value is not a null reference or empty string.
    The Name property must be initialized before using an instance of the Cookie class. The following characters are reserved and cannot be used for this attribute value: equal sign, semicolon, comma, new line (\n), carriage return (\r), tab (\t). The dollar sign ($) character cannot be the first character.
  • When setting the Port property for a cookie, make sure the value is valid and enclosed in double quotes.
    The Port attribute restricts the ports to which a cookie may be sent. The default value means no restriction. Setting the property to an empty string ("") restricts the port to the one used in the HTTP response. Otherwise the value must be a string in quotation marks that contains port values delineated with commas.
  • When setting the Value property for a cookie, make sure the value is not null.
    The following characters are reserved and cannot be used for this property: semicolon, comma.

See Also

Tasks

How to: Find Out More About an Exception with the Exception Assistant
How to: Write a Cookie

Reference

CookieException