davearia Posted March 23, 2005 Posted March 23, 2005 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. Quote
kahlua001 Posted March 23, 2005 Posted March 23, 2005 Write a test cookie, redirect them to a page where it checks for this cookie. If it is there, then they can accept cookies from you. Quote
davearia Posted March 23, 2005 Author Posted March 23, 2005 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. Quote
kahlua001 Posted March 23, 2005 Posted March 23, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.