Solved

Checking browser capabilities

Posted on 2010-08-22
9
622 Views
Last Modified: 2012-05-10
Hi!

I have a page in my website that requires Cookies, Java Applets (JRE) and JavaScript.

I tried System.Web.HttpBrowserCapabilities browser = Request.Browser; and only if all requeriments are fulfilled, the browser redirects to the page. But even with Java disabled, the page is redirected.

            System.Web.HttpBrowserCapabilities browser = Request.Browser;

            if (browser.JavaApplets)
            {

                if (browser.Cookies)
                {

                    if (browser.EcmaScriptVersion.Major > 1)
                    {
                        Response.Redirect("~/mypage.aspx");
                    }
                    else
                    {
                        Label1.Text += "No JavaScript.";
                    }
                }
                else
                {
                    Label1.Text += "No Cookies.";
                }
            }
            else
            {
                Label1.Text += "No Java.";
            }

Open in new window


How can I check all these requirements?

Thanks in advance!
0
Comment
Question by:calypsoworld
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Expert Comment

by:fsouzabrasilrj
ID: 33496197
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33497051
Use Java to do the redirect leaving a message if it doesn't work.
0
 
LVL 28

Expert Comment

by:sybe
ID: 33499164
That is because your code only checks for what a browser *could* support, based on the browser application name. Your code does not test for what the browser actually supports.

If you want to check for javascript, then you use some javascript to see if that works.
If you want to check if java (applets) will works, then you need to have a java-applet in the page and see if that works.
etc.

In other words: check for what the browser actually does, and not what it could theoretically do.
0
 

Author Comment

by:calypsoworld
ID: 33543650
> sybe

Ok, but how to do these tests?
Thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Accepted Solution

by:
sybe earned 250 total points
ID: 33548829
this is sort of the simplest:

<script>document.write('your browser supports javascript');</script>
<noscript>your browser does <b>not</b> support javascript</noscript>

for redirecting you could use:
<script>document.location='javascriptsupported.aspx';</script>

With support for java-applets you can do the same: write an applet that will redirect the browser. If the browser is redirected, java-applets are working, if not, then the browser does not support java-applets.

0
 

Author Comment

by:calypsoworld
ID: 33549134
> sybe

Thank you very much!

What about the cookies verification? Is it possible to check if cookies are enabled on client's browser?
In my solution, I should verify all three capabilities (javascript, applets e cookies).
May I group these validations in one single page? (Like cascate ifs - all conditions passed: okpage.aspx - at least one condition failed: errorpage.aspx)

Thank you!
0
 

Author Comment

by:calypsoworld
ID: 33554874
Help, please.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 33555515
Cookies are set and get only on the page request.  If you set a cookie on this page request, you have to wait until the next page request to check it or use javascript/AJAX to send the info back to your server page.

You can check them all on one page.  Set a cookie on the initial page request.  Use the javascript and noscript tags together.  The noscript section puts up a message that users see if the javascript is not enabled.  If the javascript runs then you could use the javascript to check the cookie and put up a message about the Java Applet. Then use the javascript to load the Java Applet.  I think.  The last stage, the Java Applet can then report back to you and do the redirect to the next page.
0
 

Author Closing Comment

by:calypsoworld
ID: 33667666
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now