ASP.NET Browser Detection

windows

Guest
I'm using the following server-side script to pull the users browser type, and assign the appropriate CSS stylesheet for that user:
<%
'***Browser selector begins***
'Display stylesheet depending on browser
Dim browser, stylesheet
browser = Request.Browser.Type

'Internet Explorer browser check
if browser = "IE5" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ie5.css' />"
else if browser = "IE" or browser = "IE3" or browser = "IE4" or browser = "IE6" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ie6.css' />" 'default ie stylesheet

'Gecko-based browser check
else if browser = "Netscape5" or browser = "Netscape6" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ns56.css' />"
else if browser = "Netscape7" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ns7.css' />"
else if browser = "Netscape" or browser = "Netscape8" or browser = "Mozilla" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/mz1.css' />" 'default ns stylesheet

else if browser = "Opera7" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/op7.css' />"
else if browser = "Opera" or browser = "Opera8" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/op8.css' />" 'default op stylesheet

else
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/default.css' />" 'default main stylesheet
end if
Response.Write(stylesheet)
'***Browser selector ends***
%>
NOTE: I haven't started developing it for Mac's yet, as we only have a PC environment.

Everything works great, except that Netscape 8 and Mozilla Firefox both show up as Netscape 5 when using the "Request.Browser.Type" method (huh???). This of course results in my stylesheet for NS 5 instead of my stylesheet for NS 8.

So here are my questions:
1) Why would both of these browsers show up as NS 5 with the "Request.Browser.Type" method?
2) Once I'm hopefully able to pull NS 8/Mozilla, is there a way to specify between NS 8 and Mozilla Firefox?

I hope to hear from someone soon, as I'm kinda lost on this one. Thanks.Ok, I answered my own question after researching it further, thanks to 4guysfromrolla.com.

Concerning IE 5.01 vs. 5.5, I needed to use the "Request.Browser.Version" method to pull the specific version instead of just the browser type. Now I can specify which stylesheet to use between the two.

Concerning NS 8 vs. Mozilla Firefox, I read several articles & posts mentioning the issues that the beta-version of NS 8 has been having, so I'm not going to worry about it for now. The only different between the two is the margin of an image in my top-border, and it's not a big deal. So I'll just use the same stylesheet for both of them for now until a full working version is uploaded.

Here's the code that I ended up with:
<%
'***Browser selector begins***
'Display stylesheet depending on browser
Dim browser_type, browser_version, stylesheet
browser_type = Request.Browser.Type
browser_version = Request.Browser.Version

'Internet Explorer browser check
if browser_version = "5.01" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ie5.css' />"
else if browser_version = "5.5" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ie55.css' />"
else if browser_type = "IE" or browser_type = "IE3" or browser_type = "IE4" or browser_type = "IE6" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ie6.css' />" 'default ie stylesheet

'Gecko-based browser_type check
else if browser_type = "Netscape5" or browser_type = "Netscape6" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ns56.css' />"
else if browser_type = "Netscape7" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/ns7.css' />"
else if browser_type = "Netscape" or browser_type = "Netscape8" or browser_type = "Mozilla" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/mz1.css' />" 'default ns stylesheet

else if browser_type = "Opera7" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/op7.css' />"
else if browser_type = "Opera" or browser_type = "Opera8" Then
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/op8.css' />" 'default op stylesheet

else
stylesheet = "<link rel='stylesheet' href='http://www.webdeveloper.com/forum/archive/index.php/styles/css/default.css' />" 'default main stylesheet
end if
Response.Write(stylesheet)
'***Browser selector ends***
%>Really you do not need to make a distinction between the newer ns and mozille. Because anything after ns4 is on the gecko framework... hence mozilla and ns will have the same exact box model. You only really need to be able to tell ie about from the gecko browsers, and opera, konqueror, safari, and then others.

I tend to prefer to just not even bother with server side browser identification. I just try to make my css work about right for them all and do minor hacking. But are you making a pixil perfect layout or something?Really you do not need to make a distinction between the newer ns and mozille. Because anything after ns4 is on the gecko framework... hence mozilla and ns will have the same exact box model. You only really need to be able to tell ie about from the gecko browsers, and opera, konqueror, safari, and then others.

I've found that to be almost all true, but both NS8 and Firefox interpret the width margins of an image on my site differently. So unless I was a big line to stick out for NS users, I'll have to create two separate stylesheets.
NOTE: I know that I could create a conditional statement within the CSS stylesheet itself, but that process doesn't seem to do well when debugging.

I tend to prefer to just not even bother with server side browser identification. I just try to make my css work about right for them all and do minor hacking. But are you making a pixil perfect layout or something?

I was waiting for someone in this forum to say something about that. I attempted to create one stylesheet for all browser types, but found that to be impossible when it comes to how IE and Mozilla Firefox interpret margins. Everything else was fairly similar.

My goal for my site is to have it work properly and thoroughly for as many of its users as possible. If I was to choose to develop only for IE, then I'd be forced to create a stylesheet that's not up-to-par with other gecko-based stylesheets. The one browser that I've had the most difficulty with has to be IE. I was hoping to create one stylesheet for all gecko-based browsers, but DFirefox, NS7+, and Opera all interpret margins a bit differently, which makes for an ugly and unusable website. And I'd rather do this than have to constantly update hacks created for these same browsers, which I've heard is a pain from several current developers that use that practice.

So I've decided, after suggestion through another thread, to stick with IE5+, Firefox, NS7+, and Opera7+ for Windows, and IE5+, NS7+ and Safari for Mac OS's. That's the plan, and unless some major uniformity in CSS interpretation miraculously occurs between all of these browsers, I'll stick with my plan, unless you can suggest another option....another note:

For some reason, that server-side method interprets all Netscape and Mozilla browser types to be "Netscape5". This doesn't make any sense.well is this layout pixil perfect? I have never found something that I couldn't just hack... the only thing that I have ever really really had problems with was a fluid pixil perfect layout. Of course I was not using just one method, I was using top left bottom right positioning with margins and floats.
 
Back
Top