Detecting if Browser Accepts Cookies & JavaScript

S

SHarris

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 is configured to run JavaScript?
4. Where would we put this code?

Thanks in advance!
 
J

Juan T. Llibre

Use

Request.Browser.Cookies
and
Request.Browser.JavaScript

If the value returned is true, they are enabled.
If false they are not enabled.

PLace it in the login page's Page_Load,
and redirect as appropiate ( maybe to a page
which tells the user that they are a requisite. )
 
S

SHarris

Thanks Juan! We'll check it out.


Juan T. Llibre said:
Use

Request.Browser.Cookies
and
Request.Browser.JavaScript

If the value returned is true, they are enabled.
If false they are not enabled.

PLace it in the login page's Page_Load,
and redirect as appropiate ( maybe to a page
which tells the user that they are a requisite. )
 
J

Juan T. Llibre

The standard way of doing this is by using
"the proof is in the pudding" programming.

If testing for cookies, issue a cookie and read it
after a redirect. If it's there, fine. If not...you know.

The same for JavaScript.
Set a variable, and test for it later in the page..
 
S

SHarris

Again, thanks for the info. But, after reviewing Request.Browser.Cookies
and Request.Browser.JavaScript, these two properties simply return true if
browser client "supports" Cookies and JavaScript, respectively. This is
good to know.

But, what we really need is a way to check and make sure the user has not
disabled Cookies and JavaScript through security settings. Any thoughts?
 
B

bruce barker

to tell if cookies are enabled, set a cookie value, and redirect to a page
that checks if the cookie is set.

to tell if javascript is enabled: try:

<html>
<head>
<META HTTP-EQUIV=Refresh CONTENT="1;
URL=http://yoursite.com/vir/jtest.aspx">
</head>
<body>
<form>
<input type=hidden id=jtest name=jtest value="no">
<script>document.getElementById('jtest').value="yes";document.forms[0].submi
t();<script>
</form>
if this page does not refresh automatically, click <a
href="nometarefresh.aspx">here</a>
</body>
</html>

-- bruce (sqlwork.com)



| Again, thanks for the info. But, after reviewing Request.Browser.Cookies
| and Request.Browser.JavaScript, these two properties simply return true if
| browser client "supports" Cookies and JavaScript, respectively. This is
| good to know.
|
| But, what we really need is a way to check and make sure the user has not
| disabled Cookies and JavaScript through security settings. Any thoughts?
|
|
| | > Use
| >
| > Request.Browser.Cookies
| > and
| > Request.Browser.JavaScript
| >
| > If the value returned is true, they are enabled.
| > If false they are not enabled.
| >
| > PLace it in the login page's Page_Load,
| > and redirect as appropiate ( maybe to a page
| > which tells the user that they are a requisite. )
| >
| >
| >
| > Juan T. Llibre
| > ASP.NET MVP
| > http://asp.net.do/foros/
| > Foros de ASP.NET en Español
| > =====================
| >
| > | > > 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 is configured to run JavaScript?
| > > 4. Where would we put this code?
| > >
| > > Thanks in advance!
| > >
| > >
| >
| >
|
|
 
J

Juan T. Llibre

You can't set a cookie and read it without
the client going back to the server ?

Back in the "classic asp" days, I used a workaround
which "tricked" you into believing it was the same page,
but what happened was that I'd set the setting cookie
in a 0 pixel display frame, and read it in the first page
the client saw, but that was just sleight of hand.

I suppose you could set a cookie in Session_OnStart,
but to retrieve it, wouldn't you need for the client to go
back to the server ?

Why do you say "alleged" ? How would you do it ?
( Without a second page being called ? )
 
C

clintonG

Poor choice of words Juan.

I've been wondering if there is an optimal way to do detection without using
redirection to avoid being penalized or banned by Google and other search
engines.

We've been wanting to load domain.com/appname/default.aspx and do utility
functions such as detection in the default.aspx and then redirect to
appname.aspx but don't know if this would result in getting slapped by
Google.

<%= Clinton Gallagher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top