HttpCookie.Name Property

Gets or sets the name of a cookie.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public string Name { get; set; }
/** @property */
public String get_Name ()

/** @property */
public void set_Name (String value)

public function get Name () : String

public function set Name (value : String)

Property Value

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

The following code 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.

int loop1;
 HttpCookie MyCookie;
 HttpCookieCollection MyCookieCollection;
 
 MyCookieCollection = Request.Cookies;
 
 for (loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
 {
    MyCookie = MyCookieCollection[loop1];
    if (MyCookie.Name == "UserName")
    {
       //...
    }
 }
    

int loop1;
HttpCookie myCookie;
HttpCookieCollection myCookieCollection;

myCookieCollection = get_Request().get_Cookies();
for (loop1 = 0; loop1 < myCookieCollection.get_Count(); loop1++) {
    myCookie = myCookieCollection.get_Item(loop1);
    if (myCookie.get_Name().equals("UserName")) {
        //...
    }
}

var myCookie : HttpCookie
var myCookieCollection : HttpCookieCollection 

myCookieCollection = Request.Cookies

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

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: