Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

I need help in detecting whether client has disabled cookies. I have tried this code:

Request.Browser.Cookies()

But this returns true whether cookies are disabled or not.

 

Please help.

 

Thanks, Dave.

Posted

Here is an update

 

I have come up with this code in the main default.aspx:

If Session("isPostBack") <> "True" Then
   Session("successfulLogin") = "False"
   Response.Cookies("TestCookie").Value = "ok"
   Response.Cookies("TestCookie").Expires = _
       DateTime.Now.AddMinutes(1)
   Response.Redirect("TestForCookies.aspx?redirect=" & _
       Server.UrlEncode(Request.Url.ToString))
End If

With this code in TestForCookies.aspx:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim redirect As String = Request.QueryString("redirect")
       Dim acceptsCookies As String
       ' Was the cookie accepted?
       If Request.Cookies("TestCookie") Is Nothing Then
           Session("cookiesEnabled") = "False"
           Response.Cookies("TestCookie").Expires = _
              DateTime.Now.AddDays(-1)
       Else
           session("cookiesEnabled") = "True"
           Response.Cookies("TestCookie").Expires = _
              DateTime.Now.AddDays(-1)
       End If
       Session("isPostBack") = "True"
       Response.Redirect("Default.aspx")
   End Sub

If I set my browser to accept cookies the code runs fine and I get the True value I expected. However, if I set my browser to disable cookies, the app crashes right at the start. Even though I have set custom errors off in my web.config and I have set up global.asax to send me the latest error. Despite this I just get the screen: The page cannot be displayed .

 

Please help.

 

Thanks, Dave.

Posted

Not sure what the page cannot be displayed problem is. But if you disable cookies, then

 

Session("isPostBack")

 

would not work since asp.net established your unique session with it via a cookie.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...