Use server code in Asp.net to solve browser compatibility problems

Source: Internet
Author: User

Use Code Determine the browser version used by the client
Response. Write (request. servervariables ["http_user_agent"]); (it seems that this is also available on ASP)
Or
Response. Write (request. useragent );

I have IE7 output:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; se 1.x;. Net CLR 2.0.50727;. Net CLR 3.0.04506.648;. Net CLR 3.5.21022; se 1.x)

Google browser output:

Mozilla/5.0 (windows; U; Windows NT 5.1; en-US) applewebkit/532.0 (khtml, like gecko) Chrome/3.0.195.38 Safari/532.0

write a public method call in the background (must be referenced) copy Code the code is as follows: public static int getbrowser ()
{< br> string browserinfo = httpcontext. current. request. useragent;
If (browserinfo. contains ("MSIE 7.0")
{// IE7
return 1;
}< br> else if (browserinfo. contains ("MSIE 6.0")
{// IE6
return 2;
}< br> else if (browserinfo. contains ("Firefox")
{// IE6
return 3;
}< br> else if (browserinfo. contains ("Chrome")
{// Google
return 4;
}< br> return 5;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.