-4

VisualBasic 2010でWebアプリを作成しましたが、CookieはInternetExplorer8を除くすべてのブラウザーで保持されます。

次の答えは問題を解決します。

4

1 に答える 1

0

Cookieの読み取りメソッドと書き込みメソッドを書き直すことで問題を解決しました。(VisualBasic2010で開発され、Windows Server 2008で実行されるWebアプリ)

sub update_cookie_string( cookie_string, cookie_subkey  )

    dim cookie_object as HttpCookie     
    if request.cookies( PROGRAM_COOKIE_NAME ) is nothing then   ' PROGRAM_COOKIE_NAME not at browser?
        cookie_object = new httpcookie( PROGRAM_COOKIE_NAME )           ' init cookie object as cookie named: PROGRAM_COOKIE_NAME
    else
        cookie_object = request.cookies( PROGRAM_COOKIE_NAME )          ' Read cookie named PROGRAM_COOKIE_NAME from page from browser
    End If

    cookie_object.Values( cookie_subkey ) = cookie_string       ' Update cookie_subkey with new value cookie_string
    cookie_object.Expires = DateTime.Now.AddDays(365)           ' set expiration for a long time
    response.Cookies.add( cookie_object )                   ' Send it back to browser for storage there.
end sub



' Retrieve stored cookie_subkey.
function get_cookie_string( byval cookie_subkey  ) 
    dim cookie_object as HttpCookie     
    if  request.cookies( PROGRAM_COOKIE_NAME ) is nothing then  ' PROGRAM_COOKIE_NAME not at browser?
        get_cookie_string = ""
    else
        get_cookie_string = Request.Cookies( PROGRAM_COOKIE_NAME )( cookie_subkey )  ' Return string value of cookie_subkey 
    End If
于 2012-08-03T14:42:34.503 に答える