IE and Netscape compatibility for ASP.NET

A

Ashwini Khanna

Hi Everybody!
I have a browser compability issue with ASP.NET pages. I have created a
small web-site in ASP.NET, tested it with IE - all was well till then. Then
my client required me to test on other browsers as well such as Netscape and
Mozzila. The page gets displayed ont hem but the formatting goes for a toss!
Does anyone know a work around for it? I remember when we use to do ASP
programming - we use to write client side Javascript code to detect the
browser and then execute the appropiate sensitive piece of code for
different browsers. Does the same need to be done in ASP.NET or is there
some new concept as well?

Any help would be appreciated...

Thanks and Regards,
Ashwini
 
J

Juan T. Llibre

Hi, Ashwini.

In ASP.NET, you can use Request.Browser to identify browser
capabilities, and redirect the user based on the results.

Here's a sample detection page.

detect.aspx:
------------------
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
ltlBrowserName.Text = Request.Browser.Type & ", " & Request.Browser.Platform
ltlAllData.Text = "Type = " & Request.Browser.Type & "<br>"
ltlAllData.Text &= "Name = " & Request.Browser.Browser & "<br>"
ltlAllData.Text &= "Version = " & Request.Browser.Version & "<br>"
ltlAllData.Text &= "Major Version = " & Request.Browser.MajorVersion & "<br>"
ltlAllData.Text &= "Minor Version = " & Request.Browser.MinorVersion & "<br>"
ltlAllData.Text &= "Platform = " & Request.Browser.Platform & "<br>"
ltlAllData.Text &= "Is Beta = " & Request.Browser.Beta & "<br>"
ltlAllData.Text &= "Is Crawler = " & Request.Browser.Crawler & "<br>"
ltlAllData.Text &= "Is AOL = " & Request.Browser.AOL & "<br>"
ltlAllData.Text &= "Is Win16 = " & Request.Browser.Win16 & "<br>"
ltlAllData.Text &= "Is Win32 = " & Request.Browser.Win32 & "<br>"
ltlAllData.Text &= "Supports Frames = " & Request.Browser.Frames & "<br>"
ltlAllData.Text &= "Supports Tables = " & Request.Browser.Tables & "<br>"
ltlAllData.Text &= "Supports Cookies = " & Request.Browser.Cookies & "<br>"
ltlAllData.Text &= "Supports VB Script = " & Request.Browser.VBScript & "<br>"
ltlAllData.Text &= "Supports JavaScript = " & Request.Browser.JavaScript & "<br>"
ltlAllData.Text &= "Supports Java Applets = " & Request.Browser.JavaApplets & "<br>"
ltlAllData.Text &= "CDF = " & Request.Browser.CDF & "<br>"
End Sub
</script>
<html>
<body>
Your browser is: <asp:literal id="ltlBrowserName" runat="server" />
<p>
<b><u>Here is your browser's information:</u></b><br />
<asp:literal runat="server" id="ltlAllData" />
</body>
</html>
---------------

It's very easy to redirect based on the results of Request.Browser:

Dim browserType As String = Request.Browser.Type
If browserType = "Netscape" Then
response.redirect("PageForNetscapeUsers.aspx")
End if

You could also use a Case statement to determine different redirect pages,
based on the several possibilities you're interested in, if you're interested in
creating custom pages for more than one browser.

Your custom browser pages could just be the very same page,
copied to a different filename, with the @Page directive clienttarget
set to "downlevel" :

<%@ Page ClientTarget = "downlevel" %>

That will send HTML 3.2, instead of HTML 4, output to the browser,
and should eliminate your formatting problems.

If you take a look at your machine.config file for .NET 1.1, located at
drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
you'll see a lot of browser matches specified in the browserCaps section.

If you are using .NET 1.0, the file would be at

drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

If you are using .NET 1.0, the file would be at

drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

If you haven't modified the browserCaps section, by specifying a value for it in web.config,
you will be able to filter a Netscape browser, for example, ( or any browser listed )
by using the Type, Name, Major Version or Minor Version attributes obtained
with Request.Browser, per the script supplied.

..NET 2.0 changes the detection process slightly, and the location
of individual browser detection files, so I won't discuss it here.

Good luck, and let us know how you do!



Juan T. Llibre
ASP.NET MVP
===========
 
A

Ashwini Khanna

Hi Juan,
Thanks a lot! That was very helpful!

Ashwini
Hi, Ashwini.

In ASP.NET, you can use Request.Browser to identify browser
capabilities, and redirect the user based on the results.

Here's a sample detection page.

detect.aspx:
------------------
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
ltlBrowserName.Text = Request.Browser.Type & ", " & Request.Browser.Platform
ltlAllData.Text = "Type = " & Request.Browser.Type & "<br>"
ltlAllData.Text &= "Name = " & Request.Browser.Browser & "<br>"
ltlAllData.Text &= "Version = " & Request.Browser.Version & "<br>"
ltlAllData.Text &= "Major Version = " & Request.Browser.MajorVersion & "<br>"
ltlAllData.Text &= "Minor Version = " & Request.Browser.MinorVersion & "<br>"
ltlAllData.Text &= "Platform = " & Request.Browser.Platform & "<br>"
ltlAllData.Text &= "Is Beta = " & Request.Browser.Beta & "<br>"
ltlAllData.Text &= "Is Crawler = " & Request.Browser.Crawler & "<br>"
ltlAllData.Text &= "Is AOL = " & Request.Browser.AOL & "<br>"
ltlAllData.Text &= "Is Win16 = " & Request.Browser.Win16 & "<br>"
ltlAllData.Text &= "Is Win32 = " & Request.Browser.Win32 & "<br>"
ltlAllData.Text &= "Supports Frames = " & Request.Browser.Frames & "<br>"
ltlAllData.Text &= "Supports Tables = " & Request.Browser.Tables & "<br>"
ltlAllData.Text &= "Supports Cookies = " & Request.Browser.Cookies & "<br>"
ltlAllData.Text &= "Supports VB Script = " & Request.Browser.VBScript & "<br>"
ltlAllData.Text &= "Supports JavaScript = " & Request.Browser.JavaScript & "<br>"
ltlAllData.Text &= "Supports Java Applets = " & Request.Browser.JavaApplets & "<br>"
ltlAllData.Text &= "CDF = " & Request.Browser.CDF & "<br>"
End Sub
</script>
<html>
<body>
Your browser is: <asp:literal id="ltlBrowserName" runat="server" />
<p>
<b><u>Here is your browser's information:</u></b><br />
<asp:literal runat="server" id="ltlAllData" />
</body>
</html>
---------------

It's very easy to redirect based on the results of Request.Browser:

Dim browserType As String = Request.Browser.Type
If browserType = "Netscape" Then
response.redirect("PageForNetscapeUsers.aspx")
End if

You could also use a Case statement to determine different redirect pages,
based on the several possibilities you're interested in, if you're interested in
creating custom pages for more than one browser.

Your custom browser pages could just be the very same page,
copied to a different filename, with the @Page directive clienttarget
set to "downlevel" :

<%@ Page ClientTarget = "downlevel" %>

That will send HTML 3.2, instead of HTML 4, output to the browser,
and should eliminate your formatting problems.

If you take a look at your machine.config file for .NET 1.1, located at
drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
you'll see a lot of browser matches specified in the browserCaps section.

If you are using .NET 1.0, the file would be at

drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

If you are using .NET 1.0, the file would be at

drive:\WINDOWSInstallDirectory\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

If you haven't modified the browserCaps section, by specifying a value for it in web.config,
you will be able to filter a Netscape browser, for example, ( or any browser listed )
by using the Type, Name, Major Version or Minor Version attributes obtained
with Request.Browser, per the script supplied.

.NET 2.0 changes the detection process slightly, and the location
of individual browser detection files, so I won't discuss it here.

Good luck, and let us know how you do!



Juan T. Llibre
ASP.NET MVP
===========
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top