There are no ways to detect client side configuration of the browser directly. Indeed you can check the capabilities of the browser by using
HttpRequest::Browser, but it doesn't help you at all.
As for Cookie, the only way to find out if it is usable is to create a cookie and then try to read it. If you can read, it means it's enabled else it's disabled by the client. In my code, the same principle is used.
<noscript> tag can be used to provide an alternate content for users that have disabled scripts in their browser or have a browser that don’t support client-side scripting. But using
Using the Code
The code is rather simple. The component named
BrowserChecker is defined in the file "BrowserChecker.cs".
protected void Page_Load(object sender, EventArgs e)
From the control's properties
private void CheckBrowser()
StringBuilder error = new StringBuilder();
if (this.BrowserChecker1.BrowserCookieStatus == BrowserStatus.Disabled)
if (error.Length > 0)
this.lblMessage.Text = error.ToString();
Below is the result after the button is clicked when Cookie is disabled. I used Internet Explorer 7, and disabled Cookie using Internet Explorer Developer Toolbar.
If you want to reuse this component in another project, just copy and include the file "BrowserChecker.cs" into your project, and build your application. Now in the Toolbox, you will find the control, just drag it onto your web form and you can use it.
Points of Interest
The code is very intuitive. But I'd like to mention some points below.
For checking Cookie availability, it tries to write a Cookie when rendered, and read it again when posted back.
The control inherits
Control instead of
WebControl to make it as simple as possible.
When rendered, the control checks Design Mode, and bypass Cookie setting.
Otherwise, when calling
SetCookie, there'll be error in design view, because the
HttpContext is not available in that case.
During post back, I put code into
OnInit instead of
OnLoad to make the control's properties populated earlier, so when this control is accessed from the web form's page load event handler, the properties' values are already there waiting for use.
- 9th April, 2010: Initial post