Last post Feb 16, 2020 05:55 AM by vstorpedo
Feb 15, 2020 05:35 PM|vstorpedo|LINK
Have any of you used the following code to detect if user browser accepts cookies?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim labelText As String = ""
Dim myBrowserCaps As System.Web.HttpBrowserCapabilities = Request.Browser
If (CType(myBrowserCaps, System.Web.Configuration.HttpCapabilitiesBase)).Cookies Then
labelText = "Browser supports Cookies."
labelText = "Browser does not support Cookies."
cookieValueLabel.Text = labelText
This code could be found at this link:
The problem that I’m facing is that when I turn off cookies on my browser, the code keep telling me that my browser still accepts cookies and that is incorrect.
I would appreciate your help on this.
Feb 16, 2020 03:42 AM|Rion Williams|LINK
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
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"
If Not Request.Browser.Cookies OrElse Request.Cookies("SupportCookies") Is Nothing Then
Feb 16, 2020 05:55 AM|vstorpedo|LINK
Ok, guys I decided to go with the following link to solve the problem: