Export (0) Print
Expand All

HttpCookie.Name Property

Gets or sets the name of a cookie.

[Visual Basic]
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);

Property Value

The default value is a null reference (Nothing in Visual Basic) unless the constructor specifies otherwise.

Example

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.

[Visual Basic] 
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
       '...
    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")
    {
       //...
    }
 }
    

[C++] 
int loop1;
 HttpCookie* MyCookie;
 HttpCookieCollection* MyCookieCollection;
 
 MyCookieCollection = Request->Cookies;
 
 for (loop1 = 0; loop1 < MyCookieCollection->Count; loop1++)
 {
    MyCookie = MyCookieCollection->Item[loop1];
    if (MyCookie->Name->Equals(S"UserName"))
    {
       //...
    }
 }
    

[JScript] 
var myCookie : HttpCookie
var myCookieCollection : HttpCookieCollection 

myCookieCollection = Request.Cookies

for(var i = 0; i < myCookieCollection.Count; i++){
   myCookie = myCookieCollection[i]
   if(myCookie.Name == "UserName"){
      //...
   }
}
   

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpCookie Class | HttpCookie Members | System.Web Namespace

Show:
© 2014 Microsoft