Asp.net identifies client browsers or operating systems, and asp.net clients

Source: Internet
Author: User
Tags perl script

Asp.net identifies client browsers or operating systems, and asp.net clients

1. Use UserAgent

Protected void Page_Load (object sender, EventArgs e) {// verification terminal string agent = Request. headers ["User-Agent"]; if (choose_net (agent) {Response. redirect ("/mobile/") ;}/// verification terminal public bool choose_net (String userAgent) {if (userAgent. indexOf ("Noki")>-1 | // Nokia phones and emulators userAgent. indexOf ("Eric")>-1 | // Ericsson WAP phones and emulators userAgent. indexOf ("WapI")>-1 | // Ericsson WapIDE 2.0 userAgent. indexOf ("MC21")>-1 | // Ericsson MC218 userAgent. indexOf ("AUR")>-1 | // Ericsson R320 userAgent. indexOf ("R380")>-1 | // Ericsson R380 userAgent. indexOf ("UP. B ")>-1 | // UP. browser userAgent. indexOf ("WinW")>-1 | // WinWAP browser userAgent. indexOf ("UPG1")>-1 | // UP. SDK 4.0 userAgent. indexOf ("upsi")>-1 | // another kind of UP. browser userAgent. indexOf ("QWAP")>-1 | // unknown QWAPPER browser userAgent. indexOf ("Jigs")>-1 | // unknown JigSaw browser userAgent. indexOf ("Java")>-1 | // unknown Java based browser userAgent. indexOf ("Alca")>-1 | // unknown Alcatel-BE3 browser (UP based) userAgent. indexOf ("MITS")>-1 | // unknown Mitsubishi browser userAgent. indexOf ("MOT-")>-1 | // unknown browser (UP based) userAgent. indexOf ("My S")>-1 | // unknown Ericsson devkit browser userAgent. indexOf ("WAPJ")>-1 | // Virtual WAPJAG www.wapja.de userAgent. indexOf ("fetc")>-1 | // fetchpage. cgi Perl script from www.wapcab.de userAgent. indexOf ("ALAV")>-1 | // yet another unknown UP based browser userAgent. indexOf ("Wapa")>-1 | // another unknown browser (Web based "Wapalyzer") userAgent. indexOf ("UCWEB")>-1 | // another unknown browser (Web based "Wapalyzer") userAgent. indexOf ("BlackBerry")>-1 | // another unknown browser (Web based "Wapalyzer") userAgent. indexOf ("agent")>-1 | // another unknown browser (Web based "Wapalyzer") userAgent. indexOf ("plugin")>-1 | userAgent. indexOf ("Android")>-1 | userAgent. indexOf ("mozilla")>-1) {return true;} else {return false ;}}

2. Consider asp.net mvc

There is a template for mobile.

3. Get the browser attributes

Copy codeThe Code is as follows: HttpBrowserCapabilities bc = Request. browser; Response. write ("<script language = 'javascript '> alert ('" + bc. browser + "'); </script> ");

4. js judgment

<Script type = "text/javascript"> var bro = navigator. userAgent; // alert (bro); // alert (bro. indexOf ("Windows Phone"); // iPad browser navigator. userAgent (including iPad) if (bro. indexOf ("NetFront")> 0 | bro. indexOf ("UCWEB")> 0 | bro. indexOf ("iPhone")> 0 | bro. indexOf ("Windows CE")> 0 | bro. indexOf ("MIDP-2.0")> 0 | bro. indexOf ("Android")> 0 | bro. indexOf ("Opera Mini")> 0 | bro. indexOf ("SymbianOS")> 0 | bro. indexOf ("Windows Phone")> 0) {window. open ("Wap1/Index. aspx "," _ top ");} // else if (bro. indexOf ("Windows NT")> 0) {// window. open ("NewWeb/default.html", "_ top"); //} else {window. open ("NewWeb/default.html", "_ top") ;}</script>

Let's take a look at how to obtain client information on the PC end.

/// <Summary> /// obtain the operating system name /// </summary> /// <param name = "userAgent"> </param> // <returns> </returns> private string GetOSNameByUserAgent (string userAgent) {string osVersion = "unknown"; if (userAgent. contains ("NT 10.0") {osVersion = "Windows 10";} else if (userAgent. contains ("NT 6.3") {osVersion = "Windows 8.1";} else if (userAgent. contains ("NT 6.2") {osVersion = "Windows 8";} else if (userAgent. contains ("NT 6.1") {osVersion = "Windows 7";} else if (userAgent. contains ("NT 6.1") {osVersion = "Windows 7";} else if (userAgent. contains ("NT 6.0") {osVersion = "Windows Vista/Server 2008";} else if (userAgent. contains ("NT 5.2") {if (userAgent. contains ("64") osVersion = "Windows XP"; elseosVersion = "Windows Server 2003";} else if (userAgent. contains ("NT 5.1") {osVersion = "Windows XP";} else if (userAgent. contains ("NT 5") {osVersion = "Windows 2000";} else if (userAgent. contains ("NT 4") {osVersion = "Windows NT4";} else if (userAgent. contains ("Me") {osVersion = "Windows Me";} else if (userAgent. contains ("98") {osVersion = "Windows 98";} else if (userAgent. contains ("95") {osVersion = "Windows 95";} else if (userAgent. contains ("Mac") {osVersion = "Mac";} else if (userAgent. contains ("Unix") {osVersion = "UNIX";} else if (userAgent. contains ("Linux") {osVersion = "Linux";} else if (userAgent. contains ("SunOS") {osVersion = "SunOS";} else {osVersion = HttpContext. current. request. browser. platform;} return osVersion ;}

Basically, it's quite complete. Let's make your choice based on your needs.

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.