如何清除或重置VB.Net中的Cookie值

时间:2017-07-06 20:35:06

标签: asp.net vb.net

我试图重置或清除Cookie值,而不是我正在设置的整个Cookie。所以问题是当我尝试在第1页上处理交易并转到第2页时它是好的(第一次),但是当我再次尝试在第1页进行一些更改时回到第2页,它向我展示了第一个选定的值。问题是cookie值未被清除(在第一次之后)或被重置为第二次事务(第二次)。有两种不同的方法被称为Page_Load和SavePage,因此Next按钮将触发SavePage方法,当我尝试回到Page 1 Page_load时被触发。我在这两种方法中使用的代码是。

任何人都可以帮我重置cookie值或清除设置后的第一个cookie值。感谢。

Page_Load方法

blnCSRVerify = CBool(If(chkCSRVerify.Checked = True, 1, 0))
blnCustomerDecline = CBool(If(chkCustomerDecline.Checked = True, 1, 0))
If CustomerCookie.IsCSRVerify Then
    chkCSRVerify.Checked = True
End If
If CustomerCookie.IsCustomerDecline Then
    chkCustomerDecline.Checked = True
End If
If CustomerCookie.IsSurrenderCredentials <> const_DefaultValForSurrCred Then
    If CBool(CustomerCookie.IsSurrenderCredentials) OrElse CBool(optlstVerification.YesSelected) Then
        optlstVerification.SelectedValue = CStr(1)
    Else
        optlstVerification.SelectedValue = CStr(0)
    End If
End If

SavePage()

Dim blnCSRVerify As Boolean = False
Dim blnCustomerDecline As Boolean = False
blnCSRVerify = CBool(If(chkCSRVerify.Checked = True, 1, 0))
blnCustomerDecline = CBool(If(chkCustomerDecline.Checked = True, 1, 0))

Dim objContext As HttpContext = HttpContext.Current

Dim objCustomerCookie As HttpCookie = objContext.Request.Cookies("StarsCustomer")

If blnCSRVerify Then
    objCustomerCookie.Values.Set("CSR_Verify", CStr(blnCSRVerify))
End If
If blnCustomerDecline Then
    objCustomerCookie.Values.Set("CustomerDecline", CStr(blnCustomerDecline))
End If

objCustomerCookie.Values.Set("SurrenderCredentials", optlstVerification.SelectedValue.ToString)

objContext.Response.Cookies.Add(objCustomerCookie)

0 个答案:

没有答案
相关问题