Mobile Web site, set Deny computer access

Source: Internet
Author: User

Recently, have been using Jquery-mobile + MVC to do mobile web, some experience, experience

Here's how to deny a computer access to a mobile website

The browser of the computer, not the same as the browser core of the phone, this is my idea of setting the Deny access.

Here's a way I've encapsulated a denial of access

1   Public Static classIsMobileDevice2     {3         /// <summary>4         ///whether to access the phone5         /// </summary>6         /// <param name= "Struseragent" >get models, browsers, and more</param>7         /// <returns>true is phone access; false not mobile Access</returns>8          Public Static BOOLIsMobile (stringstruseragent)9         {Ten             if(Struseragent! =NULL) One             { A                 if(System.Web.HttpContext.Current.Request.Browser.IsMobileDevice = =true|| -Struseragent.contains ("iphone") || -Struseragent.contains ("BlackBerry") || theStruseragent.contains ("Mobile") || -Struseragent.contains ("Windows CE") || -Struseragent.contains ("Opera Mini") || -Struseragent.contains ("Palm") || +Struseragent.contains ("mobi") || -Struseragent.contains ("Nokia") || +Struseragent.contains ("Samsung") || AStruseragent.contains ("SonyEricsson") || atStruseragent.contains ("mot") || -Struseragent.contains ("LG") || -Struseragent.contains ("HTC") || -Struseragent.contains ("J2ME") || -Struseragent.contains ("UCWeb") -                     ) in                     return true; -                 Else to                     return false; +             } -             Else the                 return false; *         } $}
View Code

The following is a test page in MVC

Through Request.useragent, you can get the full proxy string of the current client, I am currently using the Google Browser, can see into my own definition of an error page

You can then test successfully using Android and Apple access.

In the mobile site, due to the layout, and so on, completely different from the PC, so need to filter, I hope this simple method can help you.

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: 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.