Examples of. NET Beta2 manipulation cookies (RPM)

Source: Internet
Author: User
Tags button type datetime set cookie tostring
Cookie <%@ Page language= "VB"%>

<script language= "VB" runat= "Server" >
Const cookie_name as String = "Test-cookie-name"
Const Cookie_value as String = "Test-cookie-value"

' Declare our Cookie Object
Dim Objcookieobject as HttpCookie

Sub Btnsetcookie_onclick (Sender as Object, E as EventArgs)
' Create a cookie object-i ' m passing name and value,
' But you can also pass in a name and set the value later.
' IE. Objcookieobject = New HttpCookie (cookie_name)
Objcookieobject = New HttpCookie (cookie_name, Cookie_value)

' We already set these above!
' Objcookieobject.name = Cookie_name
' Objcookieobject.value = Cookie_value

' Additional Cookie Properties:
Objcookieobject.expires = New DateTime (2001, 11, 12)

' Normally can leave these alone.
' The defaults'll work fine for most uses.
' Objcookieobject.domain = ' www.domain.com '
' Objcookieobject.path = '/path/'
' Objcookieobject.secure = True

Response.appendcookie (Objcookieobject)
End Sub

Sub Btnremovecookie_onclick (Sender as Object, E as EventArgs)
Objcookieobject = New HttpCookie (cookie_name)

' Expire it on the ' I am ' born just so we ' re sure it ' s a date in the past.
Objcookieobject.expires = New DateTime (1974, 11, 12)

Response.appendcookie (Objcookieobject)
End Sub

Sub Btngetcookie_onclick (Sender as Object, E as EventArgs)
Objcookieobject = Request.Cookies (cookie_name)

' In Beta 1 This worked fine ... not with Beta 2.
' If not (objcookieobject = Nothing) Then

If not (Objcookieobject are nothing) Then
Lblcookiedetails.text = Objcookieobject.name

Lblcookiedetailsname.text = Objcookieobject.name
Lblcookiedetailsvalue.text = Objcookieobject.value

' For some reason I ' m has trouble with this now ...
' The setting seems to work, but I can ' t read it back.
' Anyone have any ideas? Email Me-> john@asp101.com
Lblcookiedetailsexpires.text = objCookieObject.Expires.ToString

Lblcookiedetailsdomain.text = Objcookieobject.domain
Lblcookiedetailspath.text = Objcookieobject.path
Lblcookiedetailssecure.text = objCookieObject.Secure.ToString
Lblcookiedetailshaskeys.text = objCookieObject.HasKeys.ToString
Else
Lblcookiedetails.text = "Cookie not set!"

Lblcookiedetailsname.text = ""
Lblcookiedetailsvalue.text = ""
Lblcookiedetailsexpires.text = ""
Lblcookiedetailsdomain.text = ""
Lblcookiedetailspath.text = ""
Lblcookiedetailssecure.text = ""
Lblcookiedetailshaskeys.text = ""
End If

' I ' m ignoring collections. They ' re outside the realm of this basic sample.
' Fyi:additional properties related to Cookie collections:values, Item
End Sub
</script>

<body>


<form action= "cookie.aspx" method= "POST" runat= "Server" >
<asp:button type= "Submit" id= "Btnsetcookie" text= "Set Cookie" onclick= "Btnsetcookie_onclick" runat= "Server"/>
<asp:button type= "Submit" id= "Btnremovecookie" "text=" Remove Cookie "onclick=" Btnremovecookie_onclick "runat=" Server "/>

<p>
To the cookies ' s current status for you ' ll need to click below.  This is because the response which adds or deletes the cookies happens after the ' request is ' already done. As such, those changes aren ' t available from the request collection the next request.
</p>

<asp:button type= "Submit" id= "Btngetcookie" text= "Get Cookie Details" onclick= "Btngetcookie_onclick" runat= "server "/>
</form>

<p>
<strong>details of:</strong> <asp:label id= "lblcookiedetails" runat= "Server"/>
</p>

<table border= "1" >
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td><asp:label id= "Lblcookiedetailsname" runat= "Server"/></td>
</tr>
<tr>
<td>Value</td>
<td><asp:label id= "Lblcookiedetailsvalue" runat= "Server"/></td>
</tr>
<tr>
<td>Expires</td>
<td><asp:label id= "Lblcookiedetailsexpires" runat= "Server"/></td>
</tr>
<tr>
<td>Domain</td>
<td><asp:label id= "Lblcookiedetailsdomain" runat= "Server"/></td>
</tr>
<tr>
<td>Path</td>
<td><asp:label id= "Lblcookiedetailspath" runat= "Server"/></td>
</tr>
<tr>
<td>Secure</td>
<td><asp:label id= "lblcookiedetailssecure" runat= "Server"/></td>
</tr>
<tr>
<td>has keys</td>
<td><asp:label id= "Lblcookiedetailshaskeys" runat= "Server"/></td>
</tr>
</tbody>
</table>

</body>
----------------------------------------------------
Come from asp101.com


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.