如何设置cookie并获取cookie [英] how to set cookie and get cookie

查看:111
本文介绍了如何设置cookie并获取cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置并获取饼干







受保护的子btnSubmit_Click(发件人为对象,e作为EventArgs)处理btnSubmit.Click

尝试

Dim sr As New IO.StreamReader(System.AppDomain.CurrentDomain.BaseDirectory&\\result.txt )

Dim finalresult As Integer = sr.ReadLine

sr.Close()

Response.Write(< script type =' text / javascript'> alert('你的分数是:&finalresult&');< / script>)

Dim sw As New IO.StreamWriter(System.AppDomain.CurrentDomain。 BaseDirectory&\\result.txt)

sw.WriteLine(0)

sw.Close()

Catch ex As例外

结束尝试

结束子

结束类

i am trying to set and get cookie



Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Try
Dim sr As New IO.StreamReader(System.AppDomain.CurrentDomain.BaseDirectory & "\\result.txt")
Dim finalresult As Integer = sr.ReadLine
sr.Close()
Response.Write("<script type='text/javascript'>alert('Your Score is : " & finalresult & "');</script>")
Dim sw As New IO.StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory & "\\result.txt")
sw.WriteLine(0)
sw.Close()
Catch ex As Exception
End Try
End Sub
End Class

推荐答案

设置cookie :

Set cookie:
Dim cookie As New HttpCookie("NameOfCookie")
cookie.Value = "ValueOfCookie"
Dim expiry As DateTime = DateTime.Now.AddYears(1)
cookie.Expires = expiry
Response.Cookies.Add(cookie)



读取cookie值:


Read cookie value:

Dim cookie As HttpCookie = Request.Cookies("NameOfCookie")
Dim strValue As String = cookie.Value.ToString()


这篇关于如何设置cookie并获取cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆