国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net beta2 操作cookie的例子(轉)

2024-07-10 13:05:08
字體:
來源:轉載
供稿:網(wǎng)友

<%@ 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 you can leave these alone.
        ' the defaults will 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 day i was 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 is nothing) then
            lblcookiedetails.text        = objcookieobject.name

            lblcookiedetailsname.text    = objcookieobject.name
            lblcookiedetailsvalue.text   = objcookieobject.value
            
            ' for some reason i'm having trouble with this now...
            ' the setting seems to work, but i can't read it back.
            ' anyone have any ideas? email me -> [email protected]
            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>

<html>
<body>

<h4>the cookie name we're using for this sample is: <em><%= cookie_name %></em></h4>

<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 see the cookie's current status you'll need to click below.  this is because the response which adds or deletes the cookie happens after the request is already done.  as such, those changes aren't available from the request collection until 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>
</html>
----------------------------------------------------
come from asp101.com
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 手机| 桐城市| 象州县| 安泽县| 吉安市| 镇江市| 萝北县| 拜城县| 日照市| 谢通门县| 蓬莱市| 永川市| 桓仁| 九龙城区| 香河县| 湟源县| 绥阳县| 如东县| 中超| 绍兴县| 马关县| 大同市| 兴仁县| 宁晋县| 安达市| 若尔盖县| 房山区| 乾安县| 和平县| 墨竹工卡县| 武川县| 湟源县| 芒康县| 宣恩县| 禹州市| 集贤县| 湾仔区| 九台市| 永丰县| 广德县| 浮梁县|