System.Web Namespace HttpCookie Class
Sets or retrieves the name of a cookie.
[ VB ]
Public Property Name As String
[ C# ]
public string Name {get; set;}
[ C++ ]
public: __property String* get_Name ( );
public: __property void set_Name ( String* );
[ JScript ]
public function get Name ( ) : String;
public function set Name ( String );
The default value is a null reference ( Nothing in Visual Basic ) unless the constructor specifies otherwise.
The following example receives a cookie collection from the client in the Cookie header and loops through the collection looking for a cookie with the specific name.
[ VB ]
Dim loop1 As Integer
Dim myCookie As HttpCookie
Dim myCookieCollection As HttpCookieCollection
myCookieCollection = Request.Cookies
For loop1 = 0 TO myCookieCollection.Count - 1
myCookie = myCookieCollection ( loop1 )
If myCookie.Name = "UserName" Then
' ... do whatever here ...
End If
Next loop1
[ C# ]
int loop1;
HttpCookie myCookie;
HttpCookieCollection myCookieCollection;
myCookieCollection = Request.Cookies;
For ( loop1 = 0; loop1 < myCookieCollection.Count; loop1++ ) {
myCookie = myCookieCollection [ loop1 ];
If ( myCookie.Name == "UserName" ) {
// ... do whatever here ...
}
}
HttpCookie Members