[ASP. NET] determines whether the client accessing the website is a PC or a mobile phone.

Source: Internet
Author: User
Tags servervariables

The User-agent passed by the client is used to determine whether the client accessing the website is a PC or a mobile phone. In. NET, Request. ServerVariables ["HTTP_USER_AGENT"].

For example, the normal pc is Mozilla/5.0 (Windows NT 6.1; rv: 27.0) Gecko/20100101 Firefox/27.0

Commonly used mobile phones are:

Nokia5320: Nokia 5320/UCWEB7.0.1.34/28/999

HTC Android phone: Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; HTC Desire Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) version/4.0 Mobile Safari/533.1;

IPhone: Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; zh-cn) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11

Method: Use a regular expression to match and judge. The Code is as follows:

Str_u = Request. ServerVariables [= Regex (, RegexOptions. IgnoreCase | = Regex (, RegexOptions. IgnoreCase | (! (B. IsMatch (str_u) | v. IsMatch (str_u.Substring (, Response. Redirect (, Response. Redirect (,

 

PS: No problem found.

 

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.