如何检查/检测用户是否接受cookie?使用ASP.NET(C#)

最佳答案

MSDN



写 :

Sub Page_Load()
   If Not Page.IsPostBack Then
      If Request.QueryString("AcceptsCookies") Is Nothing Then
           Response.Cookies("TestCookie").Value = "ok"
           Response.Cookies("TestCookie").Expires = _
              DateTime.Now.AddMinutes(1)
           Response.Redirect("TestForCookies.aspx?redirect=" & _
              Server.UrlEncode(Request.Url.ToString))
      Else
           labelAcceptsCookies.Text = "Accept cookies = " & _
              Request.QueryString("AcceptsCookies")
      End If
   End If
End Sub

然后阅读
Sub Page_Load()
    Dim redirect As String = Request.QueryString("redirect")
    Dim acceptsCookies As String
    ' Was the cookie accepted?
    If Request.Cookies("TestCookie") Is Nothing Then
        ' No cookie, so it must not have been accepted
        acceptsCookies = 0
    Else
        acceptsCookies = 1
        ' Delete test cookie
        Response.Cookies("TestCookie").Expires = _
           DateTime.Now.AddDays(-1)
    End If
    Response.Redirect(redirect & "?AcceptsCookies=" & acceptsCookies, _
       True)
End Sub

关于c# - 如何以编程方式测试Cookie?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1329306/

10-11 02:09