我正在编写一个ASP应用程序,其中用户数据将存储在cookie中(在24小时后到期),并且当程序运行时,它应该搜索该cookie,并将cookie中的任何内容添加到当前用户的值,然后继续通过代码。
Dim I As Integer ' iterator for cookie search
Dim foundcookie As Boolean = False ' flag if cookie found
Dim stakenow As Integer ' current stake held here
stakenow = stake.Text
Dim currentname As String
currentname = name.Text
For I = 0 To Request.Cookies.Count - 1
If Request.Cookies.Item(I).Name = currentname Then
foundcookie = True
stakenow = stakenow + Request.Cookies.Item(I).Value
currentstake.Text = currentstake.Text + stakenow.ToString
Request.Cookies.Item(I).Value = stakenow.ToString
Request.Cookies.Item(I).Expires = DateTime.Now.AddHours(24)
End If
Next
If Not foundcookie Then
Dim nameCookie As New HttpCookie(currentname)
nameCookie.Value = stakenow.ToString
nameCookie.Expires = DateTime.Now.AddHours(24)
Response.Cookies.Add(nameCookie)
currentstake.Text = currentstake.Text + stakenow.ToString
End If
此代码有效,第一次,它创建一个带有值的cookie,比如说150.然后下次运行代码并且用户"赌注"他们再次输入150,当前的赌注更新为300.但是第三次运行,如果用户输入100,我们希望用户现在的赌注是400,但是只有250.我看到这个错误来自于更新后的值未正确写回cookie,因此添加仅来自创建cookie时的原始值以及键入的值。我尝试过使用请求和响应cookie但没有运气。有什么建议吗?
答案 0 :(得分:1)
使用HttpCookieCollection.Set Method以便更新的cookie返回客户端:
SELECT Name
, SUM(Quota) Quota
FROM (
SELECT DISTINCT T1.[Name],
T0.[U_pptQuota] AS [Quota]
FROM OHEM T0
INNER JOIN OUBR T1
ON T0.[branch] = T1.[Code]
LEFT JOIN OINV T2
ON T0.[empID] = T2.[OwnerCode]
LEFT JOIN INV1 T3
ON T2.[DocEntry] = T3.[DocEntry]
) DIS