MVC4 Filter verifies client access types (mobile and PC) and mvc4filter

Source: Internet
Author: User

MVC4 Filter verifies client access types (mobile and PC) and mvc4filter

Filter:
1 /// <summary> 2 // check whether the mobile phone is accessed 3 /// </summary> 4 public class IsMobileFilter: ActionFilterAttribute 5 {6 public override void OnActionExecuting (ActionExecutingContext filterContext) 7 {8 System. web. httpBrowserCapabilitiesBase myBrowserCaps = filterContext. httpContext. request. browser; 9 bool flag = myBrowserCaps. isMobileDevice; 10 if (flag) 11 {12 string urls = "www.baidu.com"; 13 if (! String. IsNullOrEmpty (urls) 14 {15 urls = urls. Contains ("http ")? Urls. trim (): "http: //" + urls. trim (); 16 filterContext. result = new RedirectResult (urls); 17} 18 else19 {20 base. onActionExecuting (filterContext); 21} 22} 23 else24 {25 base. onActionExecuting (filterContext); 26} 27} 28}

Register global Filter in FilterConfig
      public static void RegisterGlobalFilters(GlobalFilterCollection filters)         {              filters.Add(new IsMobileFilter());         }

  

 


MVC4 mobile app development tutorial. VS2010 or VS2012 is the development tool, C # language, winform basics, recommended by talents.

I don't know whether the mobile application you are referring to is a web application or a client application. If it is a web application, it should be. net mvc directly develops web pages suitable for mobile browsing and operations. It is recommended to upgrade vs2013 and use mvc5, which introduces the bootstrap frontend response framework. The framework uses a large number of html5 features and supports response, it is ideal for developing multi-screen adaptive applications. If you are developing a client application, you should use. net mvc to develop web interfaces. The client calls the interfaces through http requests. You can consider the webapi introduced after mvc4. We recommend that you upgrade vs2013 to use webapi2 (the webapi framework of mvc4 has functions and limitations and does not support Filter such as identity authentication). Of course, you can also directly use common mvc. Json format data is recommended to be returned (the mime type is application/json, which is less redundant than xml and easier to parse on the client ). RESTful is recommended for interfaces developed by mvc.
If you are the basis of winform, we recommend that you start from asp.net. The design principle of asp.net is to make winform development and webform development experience almost the same. It is a drag-and-drop control, and double-click writing events, making the transformation very easy. However, poor writing may easily lead to lower efficiency.
 

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.