Home | Software | WebLog | Contact | Wish List

Cookie Detect (Asp.NET)

Overview

Cookie detection is a key feature to every web application. Without cookies you are left with few options for tracking or identifying users. Cookies are by far the easiest way to track users; ASP.Net does it automatically for you. Without cookies you are unable to keep a session with the user, all your Session variables become worthless.

There may be a couple of reasons why a user would not have cookies. They might be using an old browser that doesn't support cookies. They might also have disabled cookies or their employer may have disabled cookies.

You could turn on cookieless sessions in your web.config file, but this gives you an ugly looking url (example: http://joel.net/(as5g7f9dhf45k9envx612bf))

Identifying whether or not a user has cookies is the first step in figuring out what you're going to do with these users.

Simply slip this control into any webpage that requires cookies or sessions. The control has a boolean property you can test.

If you found this or any other code on this site usefull and want to show your appreciation, now you can. Thanks!

Detection Example

Cookie Status: Cookies are Enabled.


Example Code

<%@ Page language="c#" AutoEventWireup="true" %> <%@ Register TagPrefix="cc1" Namespace="Joel.Net" Assembly="Joel.Net.CookieDetect" %> <SCRIPT runat="server"> private void Page_Load(object sender, System.EventArgs e) { lblEnabled.Text = CookieDetect1.IsEnabled.ToString(); lblVersion.Text = CookieDetect1.version; } </SCRIPT> <HTML><HEAD><TITLE>Cookie Detect</TITLE></HEAD> <BODY> <FORM id="frmMain" method="post" runat="server"> <CC1:COOKIEDETECT id="CookieDetect1" runat="server" /> Cookies Enabled: <ASP:LABEL id="lblEnabled" runat="server" /> <BR> CookieDetect Version: <ASP:LABEL id="lblVersion" runat="server" /> </FORM> </BODY> </HTML></PRE>


Visual Studio Toolbox Installation

Add the control to your toolbox. Go to Tools > Customize Toolbox. Click the tab .Net Framework Components. Click on Browse, locate Joel.Net.CookieDetect.dll and click ok. You should now see "CookieDetect" in the toolbox.

post reply to this comment Comment by gurdev [Apr 10, 2006 @ 2:47 AM]
This code is not working properly on my localhost.
any suggestions
post reply to this comment Comment by xyz [Jan 24, 2008 @ 12:06 AM]
This control does not work with IE6 . When cookies are disabled it still shows as enabled.
Leave Your Comment
Name:
Email:  (gravatar enabled)
URL:
Comment:
or Cancel