473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# Client browser, cookies enabled?

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!
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 HttpBrowserCookieCheck(HttpRequest Request,
HttpResponse Response)
{
try
{
// Create cookie object
HttpCookie cookieCheck = null;

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

// 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.Cookies.Remove("HttpBrowserCookieCheck");
return true;
}
}
catch
{
return false;
}
finally
{
}
}

public void HttpBrowserCookieCreate(HttpRequest Request,
HttpResponse Response)
{
try
{
// Create cookie object
HttpCookie cookieCreate = new
HttpCookie("HttpBrowserCookieCheck");

// Set the cookies value
cookieCreate.Value = "true";

// Add the cookie
Response.Cookies.Add(cookieCreate);
}
catch
{
}
finally
{
}
}

Apr 28 '06 #1
6 7810
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(HttpRequest 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 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.


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 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.


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 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.


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("HttpBrowserCookieCheck");

// Set the cookies value
cookieCreate.Value = "true";

// Add the cookie
Response.Cookies.Add(cookieCreate);

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
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...
9
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...
0
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...
0
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...
1
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...
9
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...
2
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....
7
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...
0
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...
3
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
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...

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.