473,666 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check cookie enabled for the browser or not?

if (Request.Browse r.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 7780
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(objec t sender, EventArgs e)
{
if (this.IsCookieD isabled())
errorMsgLabel.T ext = Resources.Resou rce.BrowserDont SupportCookies;

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

if (Request.QueryS tring["cookieChec k"] == null)
{
try
{
HttpCookie c = new HttpCookie("Sup portCookies", "true");
Response.Cookie s.Add(c);

if (currentUrl.Ind exOf("?") 0)
currentUrl = currentUrl + "&cookieCheck=t rue";
else
currentUrl = currentUrl + "?cookieCheck=t rue";

Response.Redire ct(currentUrl);
}
catch
{
}
}

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

return false;
}

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

"BL" wrote:
if (Request.Browse r.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.Browse r.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(objec t sender, EventArgs e)
{
if (this.IsCookieD isabled())
errorMsgLabel.T ext = Resources.Resou rce.BrowserDont SupportCookies;

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

if (Request.QueryS tring["cookieChec k"] == null)
{
try
{
HttpCookie c = new HttpCookie("Sup portCookies", "true");
Response.Cookie s.Add(c);

if (currentUrl.Ind exOf("?") 0)
currentUrl = currentUrl + "&cookieCheck=t rue";
else
currentUrl = currentUrl + "?cookieCheck=t rue";

Response.Redire ct(currentUrl);
}
catch
{
}
}

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

return false;
}

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

"BL" wrote:
if (Request.Browse r.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
3183
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 off, the global variables are empty between pages, fine, that tells me cookies store the global variables - right? I store the values in $_session and when cookies are turned on values are passed between web pages - I can see these values in fields...
27
7111
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 a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the user accesses it (not just once and then store it in the session). If a secure app is multi-page,...
11
6036
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? Thanks Jen
7
8369
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, no if is disabled. Thanks Diego
4
1895
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. Can anybody help me out with this? private void Page_Load(object sender, System.EventArgs e) { if (!(Page.IsPostBack))
5
5296
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 post back, when I try to retreive it from Request.Cookies collection, it appears that it does not exists. This problem does not occur on several developing machines we use for developing application, but occurs in another environment (another...
3
1224
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 following Session("MyObj")=value cookies have to be enabled on the client browser. Is that true? If true where can i find that cookie in my pc directories? About the sample: there's 2 .aspx pages with just 1 label on the first page.
1
2274
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 *** below. Any ideas? <script type="text/javascript"> Set_Cookie( 'test', 'none', '', '/', '', '' ); if ( Get_Cookie( 'test' ) )
3
2589
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 directly, through a local web server and through a remote web server. By turning cookies on/off in your browser, running the file, then clicking the 'test1' or 'test2' buttons, the displayed text should accurately inform you if your cookies are On or...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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 we have to send another system

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.