Problem detecting if user browser accept cookies RRS feed


All replies

  • User281315223 posted

    What I'd recommend is taking a slightly different approach. Instead of attempting to check the browser itself to see if cookies are enabled (which could be all sorts of misleading), you might consider just attempting to set a cookie, perform a redirection, and see if you can read the cookie. This would indicate if they are supported by the browser or being explicitly disabled by the user.

    If you are going to be relying on cookies, this is likely a much safer approach. You can find a similar approach detailed below from this older post on this same forum:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
     If Me.IsCookieDisabled Then
       errorMsgLabel.Text = Resources.Resource.BrowserDontSupportCookies
     End If
    End Sub
    Private Function IsCookieDisabled() As Boolean
     Dim currentUrl As String = Request.RawUrl
     If Request.QueryString("cookieCheck") Is Nothing Then
         Dim c As HttpCookie = New HttpCookie("SupportCookies", "true")
         If currentUrl.IndexOf("?") > 0 Then
           currentUrl = currentUrl + "&cookieCheck=true"
           currentUrl = currentUrl + "?cookieCheck=true"
         End If
       End Try
     End If
     If Not Request.Browser.Cookies OrElse Request.Cookies("SupportCookies") Is Nothing Then
       Return True
     End If
     Return False
    End Function

    Sunday, February 16, 2020 3:42 AM
  • User426001450 posted

    Ok, guys I decided to go with the following link to solve the problem:


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 16, 2020 5:55 AM