473,467 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to check cookie enabled for the browser or not?

if (Request.Browser.Cookies)
{
// Cookies supported
}
else
{
// Web browser not supports cookies
}
Code above will tell you does web browser supports cookie technology, but a
visitor could disable cookies in web browser's privacy settings. In that
case, Request.Browser.Cookies will still return true but your cookies will
not be saved.

what is the best way in asp.net 2.0 to check cookies disable or enabled in
web browser's privacy settings ?

Thank you.
BL
Sep 8 '08 #1
3 7768
I could not say if this is the "best" way but one way I see often is to write
a test cookie on page load and then post back to the same url checking if you
can retrieve the cookie. The code below is from the forums on asp.net and
posted by Fredrik Normen. It illustrates in general how this strategy could
be implemented.

Hopefully you can use something like this to solve your problem. Otherwise,
you might have to use javascript to check if cookies are enabled and then
post that to a form/url to be stored in the session state.

Good Luck.

================================================== =
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsCookieDisabled())
errorMsgLabel.Text = Resources.Resource.BrowserDontSupportCookies;

}
private bool IsCookieDisabled()
{
string currentUrl = Request.RawUrl;

if (Request.QueryString["cookieCheck"] == null)
{
try
{
HttpCookie c = new HttpCookie("SupportCookies", "true");
Response.Cookies.Add(c);

if (currentUrl.IndexOf("?") 0)
currentUrl = currentUrl + "&cookieCheck=true";
else
currentUrl = currentUrl + "?cookieCheck=true";

Response.Redirect(currentUrl);
}
catch
{
}
}

if (!Request.Browser.Cookies || Request.Cookies["SupportCookies"] ==
null)
return true;

return false;
}

================================================== =

"BL" wrote:
if (Request.Browser.Cookies)
{
// Cookies supported
}
else
{
// Web browser not supports cookies
}
Code above will tell you does web browser supports cookie technology, but a
visitor could disable cookies in web browser's privacy settings. In that
case, Request.Browser.Cookies will still return true but your cookies will
not be saved.

what is the best way in asp.net 2.0 to check cookies disable or enabled in
web browser's privacy settings ?

Thank you.
BL
Sep 8 '08 #2
this is usually done with a sniffer page. you set a value in the cookie and
redirect back to the same page and check to see if the cookie has a value.
usually you'd also check for javascript and any plugins you need at the same
time. you can get a commerical sniffer if you google.

-- bruce (sqlwork.com)
"BL" wrote:
if (Request.Browser.Cookies)
{
// Cookies supported
}
else
{
// Web browser not supports cookies
}
Code above will tell you does web browser supports cookie technology, but a
visitor could disable cookies in web browser's privacy settings. In that
case, Request.Browser.Cookies will still return true but your cookies will
not be saved.

what is the best way in asp.net 2.0 to check cookies disable or enabled in
web browser's privacy settings ?

Thank you.
BL
Sep 8 '08 #3
Thank you for your quick reply

your code is deduct cookies status perfect in firefox and other browsers but
in internet explorer 6 and 7 this function always return false weather
cookies enabled or disabled

Thanks again

BL

"GridView Newbie" wrote:
I could not say if this is the "best" way but one way I see often is to write
a test cookie on page load and then post back to the same url checking if you
can retrieve the cookie. The code below is from the forums on asp.net and
posted by Fredrik Normen. It illustrates in general how this strategy could
be implemented.

Hopefully you can use something like this to solve your problem. Otherwise,
you might have to use javascript to check if cookies are enabled and then
post that to a form/url to be stored in the session state.

Good Luck.

================================================== =
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsCookieDisabled())
errorMsgLabel.Text = Resources.Resource.BrowserDontSupportCookies;

}
private bool IsCookieDisabled()
{
string currentUrl = Request.RawUrl;

if (Request.QueryString["cookieCheck"] == null)
{
try
{
HttpCookie c = new HttpCookie("SupportCookies", "true");
Response.Cookies.Add(c);

if (currentUrl.IndexOf("?") 0)
currentUrl = currentUrl + "&cookieCheck=true";
else
currentUrl = currentUrl + "?cookieCheck=true";

Response.Redirect(currentUrl);
}
catch
{
}
}

if (!Request.Browser.Cookies || Request.Cookies["SupportCookies"] ==
null)
return true;

return false;
}

================================================== =

"BL" wrote:
if (Request.Browser.Cookies)
{
// Cookies supported
}
else
{
// Web browser not supports cookies
}
Code above will tell you does web browser supports cookie technology, but a
visitor could disable cookies in web browser's privacy settings. In that
case, Request.Browser.Cookies will still return true but your cookies will
not be saved.

what is the best way in asp.net 2.0 to check cookies disable or enabled in
web browser's privacy settings ?

Thank you.
BL
Sep 8 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TG | last post by:
This is more of a pain than I thought it would be. I need a simple code segment to determine whether a browser accepts cookies or not. When I pass variables between pages when cookies are turned...
27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
11
by: Jennifer | last post by:
Is there a way to check for to see if the user has session cookies enabled? I know how to check to see if they have cookies in general enabled, but how do you test for just session cookies? ...
7
by: Diego | last post by:
Hi My question is if exists any way to check if javascript is disabled on the client browser, I have tried with browser.javascript but this only return to me if the browser has the capability,...
4
by: mike parr | last post by:
I'm trying to do a check to see if the client browser has cookies enabled. But my code below always gives me the value for acceptsCookies = true, whether the machine has cookies enabled or not. ...
5
by: Miljana | last post by:
Hi, I have one problem with cookies in ASP.NET application. It seems that I can not retreive cookie from Request.Cookies collection. I put cookie in Response.Cookies collection, and after page...
3
by: rodchar | last post by:
Hey all, I'm trying to gain more knowledge about state management and I found an MSDN Help article about cookies. I posted the short sample below. From what I read in the article if you do the...
1
by: StevePBurgess | last post by:
I am using a script (see below) to check if cookies are enabled on my website. The script seems to work but I get an Object Expected error. The error repor says it is at the line incidated by the...
3
by: WayneH | last post by:
Hi - I'm trying to use javascript to determine if a user's browser has cookies enabled or not. To test: copy this code into a file with a 'html' extension, and load it into your IE browser...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.