February 14, 2006
Checking that cookies are enabled in ASP.NET
Create a file called CheckCookie.ascx on your site. Copy and paste this text into the file:
<%@ Control Language="vb" AutoEventWireup="false" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (Me.IsPostBack) Then
If Me.Request.Cookies.Item(Me.UniqueID) Is Nothing Then
If Not Me.FindControl("message") Is Nothing Then
Me.FindControl("message").Visible = True
End If
End If
Else
Response.Cookies.Add(New HttpCookie(Me.UniqueID))
End If
End Sub
</script>
<div id="message" runat="server" visible="false">
You do not have cookies enabled.
</div>
This is called an ASP.NET user control. It is sort of like an HTML include file + script. Each time there is a postback (clicking Add to Cart for example) it will check for a cookie. If this cookie does not exist it will display the message.
Now add this user control to the pages where you want the message to appear when they do not have cookies enabled. To add the control, add this line to the top of the file:
<%@ Register TagPrefix="ss" TagName="CheckCookie" Src="CheckCookie.ascx" %>
And add this line where you want the message to appear:
<ss:CheckCookie id="cc" runat="server" />
To test this I used FireFox and disabled all cookies. You can disable all cookies in IE, but this only disables new cookies. To test this in IE you would have to disable all cookies and delete all cookies.
This site looks much better in a browser that supports current web standards, but it is accessible to any browser.
Download one now
Some parts of this site will not work effectively on this older browser.
Please consider
updating your browser