HttpCookieCollection.GetKey(Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the key (name) of the cookie at the specified numerical index.
public:
System::String ^ GetKey(int index);
public string GetKey (int index);
member this.GetKey : int -> string
Public Function GetKey (index As Integer) As String
Parameters
- index
- Int32
The index of the key to retrieve from the collection.
Returns
The name of the cookie specified by index
.
Examples
The following example returns each cookie from the cookie collection, checks whether it is named "LastVisit", and, if "LastVisit" is found, updates its value to the current date and time.
int loop1;
HttpCookieCollection MyCookieCollection = Response.Cookies;
for(loop1 = 0; loop1 < MyCookieCollection.Count; loop1++)
{
if(MyCookieCollection.GetKey(loop1) == "LastVisit")
{
MyCookieCollection[loop1].Value = DateTime.Now.ToString();
MyCookieCollection.Set(MyCookieCollection[loop1]);
}
}
Dim loop1 As Integer
Dim MyCookie As HttpCookie
Dim MyCookieCollection As HttpCookieCollection = Request.Cookies
For loop1 = 0 To MyCookieCollection.Count - 1
If MyCookieCollection.GetKey(loop1) = "LastVisit" Then
MyCookieCollection(loop1).Value = DateTime.Now().ToString()
MyCookieCollection.Set(MyCookieCollection(loop1))
Exit For
End If
Next loop1
Applies to
Współpracuj z nami w serwisie GitHub
Źródło tej zawartości można znaleźć w witrynie GitHub, gdzie można również tworzyć i przeglądać problemy i żądania ściągnięcia. Więcej informacji znajdziesz w naszym przewodniku dla współtwórców.