Click or drag to resize

CookieExtensionsAddEncodedCookie Method

Create a cookie and add it to the response where the cookie value may contain characters that are invalid in a cookie. Use GetEncodedCookieValue(HttpRequest, String) when retrieving values from such cookies. You can also use the AddCookie(HttpResponse, String, String, CookieAttrs, String, Int32) overload which supports Secure cookies as well as encoding.

Namespace:  NetQuarry.Net
Assembly:  EAP.Core (in EAP.Core.dll) Version: 2.0.0.0 (4.6.8.0)
Syntax
public static void AddEncodedCookie(
	this HttpResponse response,
	string name,
	string value,
	string domain = null,
	int expiresDays = 0
)

Parameters

response
Type: System.WebHttpResponse
The response.
name
Type: SystemString
The cookie name.
value
Type: SystemString
The cookie value.
domain (Optional)
Type: SystemString
The optional cookie domain.
expiresDays (Optional)
Type: SystemInt32
The optional cookie expiration, in days from the current date. This is set on the cookie only if non-zero.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HttpResponse. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
See http://stackoverflow.com/questions/1969232/allowed-characters-in-cookies for a discussion of problematic cookie values that require encoding. The value is encoded using the .Net HttpUtility.UrlEncode() method which is at least approximately equivalent to the javascript encodeURIComponent() method.
See Also