473,770 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Client browser, cookies enabled?

I started off by trying to use the HttpCapabilitie sBase.Cookies
Property (Note: This property is new in the .NET Framework version 2.0)
however it kept on returning true even when I disabled cookies in both
FireFox and Internet Explorer.

After a bit of googling I found that a lot of people were creating
cookies, then re-reading them; obviously if they could re-read the
cookie then they knew that the client's browser accepts cookies!
Simple. However, after writing a similar class to the ones I viewed
online, I'm still getting true returned, even when I disable cookies in
both FireFox and Internet Explorer.

With FireFox's cookie dialog open, I ran the application with cookies
turned off and indeed, FireFox showed no cookies were stored during the
HTTP request, however my code once again returned true!

When running the application with cookies turned on, FireFox showed one
cookie stored during HTTP request, and the code returned true.

Please advise.

public bool HttpBrowserCook ieCheck(HttpReq uest Request,
HttpResponse Response)
{
try
{
// Create cookie object
HttpCookie cookieCheck = null;

// Request cookie from client's browser
cookieCheck =
Request.Cookies["HttpBrowserCoo kieCheck"];

// Check whether the cookie exists on client's
browser
if (cookieCheck == null) // Client browser does not
support cookies !! noooo !!
{
return false;
}
else // Client browser supports cookies !! yay !!
{
// Remove test cookie

Response.Cookie s.Remove("HttpB rowserCookieChe ck");
return true;
}
}
catch
{
return false;
}
finally
{
}
}

public void HttpBrowserCook ieCreate(HttpRe quest Request,
HttpResponse Response)
{
try
{
// Create cookie object
HttpCookie cookieCreate = new
HttpCookie("Htt pBrowserCookieC heck");

// Set the cookies value
cookieCreate.Va lue = "true";

// Add the cookie
Response.Cookie s.Add(cookieCre ate);
}
catch
{
}
finally
{
}
}

Apr 28 '06 #1
6 7850
I have downloaded HTTP Analyzer to see if I can get a better
understanding of what's going on. However if anything it's confused me
more.

If I disable cookies in FireFox and run the web application, FireFox's
cookie dialogue tells me no cookies were recieved/stored, which is
correct. However HTTP Analyzer shows me the cookie that I sent in the
script above, so ... still a bit lost.

Basically, I need to get my code to request a cookie from the client's
browser, if it doesn't exist; return false. Which I believe the above
code should do?

Apr 28 '06 #2
Right, the method below checks whether or not the specified cookie
exists. The problem is, is that the cookie DOES NOT exist, I'm looking
at the cookies window in FireFox and it's empty, but this code is
continually returning true..

// retrieve cookie value
public bool GetCookie(HttpR equest Request)
{
HttpCookie MyCookie = Request.Cookies["MyCookie"];

// check cookie exists
if(MyCookie != null)
{
return true;
}
else
{
return false;
}
}

Please advise.
dawson wrote:
I have downloaded HTTP Analyzer to see if I can get a better
understanding of what's going on. However if anything it's confused me
more.

If I disable cookies in FireFox and run the web application, FireFox's
cookie dialogue tells me no cookies were recieved/stored, which is
correct. However HTTP Analyzer shows me the cookie that I sent in the
script above, so ... still a bit lost.

Basically, I need to get my code to request a cookie from the client's
browser, if it doesn't exist; return false. Which I believe the above
code should do?


Apr 28 '06 #3
> I started off by trying to use the HttpCapabilitie sBase.Cookies
Property (Note: This property is new in the .NET Framework version 2.0)
however it kept on returning true even when I disabled cookies in both
FireFox and Internet Explorer.


The Capabilities class does not test the current browser, rather it
reads the browser identification string to make a guess as to what
browser is making the request. From that guess it will report that
"this" browser is *capable* of using cookies etc, not whether it is
actually enabled.
Hans Kesting
Apr 28 '06 #4
Thank you, fortunatly I stopped using it right at the beginning of the
thread.

Could you read my other posts and see if you can see what the problem
is?

Thanks.

Hans Kesting wrote:
I started off by trying to use the HttpCapabilitie sBase.Cookies
Property (Note: This property is new in the .NET Framework version 2.0)
however it kept on returning true even when I disabled cookies in both
FireFox and Internet Explorer.


The Capabilities class does not test the current browser, rather it
reads the browser identification string to make a guess as to what
browser is making the request. From that guess it will report that
"this" browser is *capable* of using cookies etc, not whether it is
actually enabled.
Hans Kesting


Apr 28 '06 #5
Anyone please?

dawson wrote:
Thank you, fortunatly I stopped using it right at the beginning of the
thread.

Could you read my other posts and see if you can see what the problem
is?

Thanks.

Hans Kesting wrote:
I started off by trying to use the HttpCapabilitie sBase.Cookies
Property (Note: This property is new in the .NET Framework version 2.0)
however it kept on returning true even when I disabled cookies in both
FireFox and Internet Explorer.


The Capabilities class does not test the current browser, rather it
reads the browser identification string to make a guess as to what
browser is making the request. From that guess it will report that
"this" browser is *capable* of using cookies etc, not whether it is
actually enabled.
Hans Kesting


May 2 '06 #6
After reading your original post again, I noticed this part:

HttpCookie cookieCreate = new HttpCookie("Htt pBrowserCookieC heck");

// Set the cookies value
cookieCreate.Va lue = "true";

// Add the cookie
Response.Cookie s.Add(cookieCre ate);

With this code you will create a "session" cookie, one that will not
be persisted when the browser closes. I'm not sure what happens to
these cookies when you tell FireFox to "ignore cookies". It is
possible that the "ignore" only works on persisted cookies.
Try adding an expiry-date (doesn't have to be later than "tomorrow")
and see if that helps.
Hans Kesting
May 2 '06 #7

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

Similar topics

2
4715
by: Tom | last post by:
Hi, I would like to use the standard PHP sessions and I understand they rely on the target web browser to support session cookies. I have tried the following code: <? session_start(); if (!session_id()) { //no support for session
9
2106
by: Carter Smith | last post by:
http://www.icarusindie.com/wiki/index.php/Server-Side_Javascript_Check Sample source included This method requires that your pages are PHP enabled and you have mySQL. Although I suppose you could also use PHP sessions (not cookies as they're client editable). You could actually use any server side scripting language such as Perl or ASP and any database like MS SQL Server. I prefer PHP and MySQL.
0
1254
by: Sri. | last post by:
Hi I am trying to figure out how to test whether my browser cookies are enabled. I used the code from the following page http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchaspnetcookies101.as Basically, it tells me to create a cookie and test the cookie from another page. However, in IE 6.0, if I set my privacy setting to a High level so as to block all cookies, the code always returns that the...
0
1271
by: Sri | last post by:
Hi I am trying to figure out how to test whether my browser cookies are enabled. I used the code from the following page http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchaspnetcookies101.as Basically, it tells me to create a cookie and test the cookie from another page. However, in IE 6.0, if I set my privacy setting to a High level so as to block all cookies, the code always returns that the...
1
3343
by: Peter Row | last post by:
Hi, I have a web app, there is only really 1 aspx page (that the user never sees) the rest of the code is done in a DLL that implements HttpHandler. My app (which is a porting job from Vb6 webclasses) needs to use session cookies (i.e. when all browser windows are closed the cookies disappear) however in my code the cookies disappear after a round trip to the client browser, i.e: Browser
9
3061
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET application, how can we code the project to check to make sure the browser accepts cookies? 2. Where would we put this code? In Global.asax? 3. Using C# in an ASP.NET application, how can we code the project to detect and make sure the browser...
2
1839
by: rk325 | last post by:
I have a question about cookies & browser permissions and turning off cookies when creating a web site (cookieless mode in web.config). I have a web site that of course uses Session variables. But we decided to turn off the cookieless mode because the client specifically said her browser did not allow cookies. Anyway, when searching about it, I found out that by setting cookieless = true the session cookie is embedded into the URL sent...
7
3213
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I think the username can be read with user.identity.name.
0
541
by: dawson | last post by:
I started off by trying to use the HttpCapabilitiesBase.Cookies Property (Note: This property is new in the .NET Framework version 2.0) however it kept on returning true even when I disabled cookies in both FireFox and Internet Explorer. After a bit of googling I found that a lot of people were creating cookies, then re-reading them; obviously if they could re-read the cookie then they knew that the client's browser accepts cookies!...
3
7789
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
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
7451
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
6710
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
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.