Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Conditional Statement, User Agent, Lower Case and Print to Screen

Browser detection code in PHP, translate to ASP.Net

6:03 pm on Jan 26, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 10, 2006
posts: 47
votes: 0

I am really unfamiliar with ASP code. And I also do not know if the code for ASP.Net is different from ASP.

But I basically need to do this PHP code I wrote, in it's equivalent ASP and ASP.Net code (if they are different)

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"webkit")) {
echo "<link href=\"http://www.example.com/csspath/layoutwebkit.css" rel=\"stylesheet\" type=\"text/css\" media=\"screen, projection\" />";

I tried researching for this first, looking for strpos, user-agent, but I might not be able to put it all together correctly. And if the variable values are not case-sensitive, maybe the strtolower is not needed.

I know there are other ways to make CSS more cross-browser compatible, but the site I am working on is just so messed up and I do not want to do everything from scratch and decided to do browser user-agent detection.

8:08 pm on Jan 26, 2009 (gmt 0)


WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
votes: 3

In Asp.net you can use the following two properties of the Request.Browser object.
"Request.Browser.Browser" to return the browser name.
"Request.Browser.Version" to return the browser version.

Asp.net has a built in browser identification system which can be used on a per page bases. So you do not need to try and figure out for your self the Browser and version details from the User-Agent.

Here is a MS KB Article [support.microsoft.com] on topic.