asp.net and JavaScript to determine whether the phone access method _ practical skills

Source: Internet
Author: User

This article is an example of how asp.net and JavaScript determine whether a cell phone is accessible. Share to everyone for your reference, specific as follows:

<summary>
///to Judge mobile phone users useragent
///</summary>
///<returns></returns>
private bool IsMobile ()
{
  HttpContext context = HttpContext.Current;
  If (context!= null)
  {
    HttpRequest request = context. Request;
    if (request). Browser.ismobiledevice) return
      true;
    String mobileuseragent=system.configuration.configurationmanager.appsettings["Mobileuseragent"];
    Regex Mobile_regex = new Regex (mobileuseragent);
    if (string. IsNullOrEmpty (Request. useragent) | | Mobile_regex. IsMatch (Request. Useragent.tolower ()) return
      true;
  }
  return false;
}

The following is the Web.config configuration inside the

Copy Code code as follows:
<add key= "mobileuseragent" value= "iphone|android|nokia|zte|huawei|lenovo|samsung|motorola|sonyericsson|lg| philips|gionee|htc|coolpad|symbian|sony|ericsson|mot|cmcc|iemobile|sgh|panasonic|alcatel|cldc|midp|wap|mobile| Blackberry|windows Ce|mqqbrowser|ucweb "/>

<script>
var system ={  Win:false,  mac:false,  xll:false  };
Detection Platform
var p = navigator.platform;
System.win = P.indexof ("win") = = 0;
System.mac = P.indexof ("mac") = = 0;
system.x11 = (P = = "X11") | | (P.indexof ("Linux") = = 0);
Jump Statement
if (system.win| | system.mac| | SYSTEM.XLL)
{
  alert (SYSTEM.MAC)
}
else
{
  window.location.href= "mobile Access Address";
}
</script>

More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

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.