这是读写ASP.NET Cookie多个子项的可靠方法吗?

时间:2019-03-04 16:23:39

标签: asp.net cookies

这是我的代码。看来还可以。
但我担心它是否可靠。

sub put_cookie_string( cookie_value, subkeyName  )
    If (Request.Cookies( PROGRAM_COOKIE_NAME) IS Nothing) Then            
        Response.Cookies( PROGRAM_COOKIE_NAME )( subkeyName ) = cookie_value
        Response.Cookies( PROGRAM_COOKIE_NAME).Expires = DateTime.Now.addyears(50)
    else
        Dim aCookie As HttpCookie = Request.Cookies( PROGRAM_COOKIE_NAME )
        aCookie.Values.Set( subkeyName, cookie_value )
        aCookie.Expires = DateTime.Now.addyears(50)
        Response.Cookies.Add( aCookie )
    end if
end sub



function get_cookie_string( byval subkeyName  ) 
    get_cookie_string = ""
    If (Request.Cookies( PROGRAM_COOKIE_NAME) IsNot Nothing) Then
        If (Request.Cookies( PROGRAM_COOKIE_NAME)( subkeyName) IsNot Nothing) Then
            get_cookie_string =     Request.Cookies( PROGRAM_COOKIE_NAME)( subkeyName )
        End If
    End If
end function

0 个答案:

没有答案