仅在来自手机时才返回响应

时间:2018-01-19 05:33:42

标签: .net asp.net-mvc cordova extjs phonegap

我们正在开发一个带有phonegap的移动应用程序,extjs和后端是.net代码。现在我想确保每个访问.net代码的请求来自移动应用程序。如果它来自任何其他来源,我们不应该返回任何回复。 任何人都可以告诉我们如何检查请求是否来自移动应用/移动浏览器?

3 个答案:

答案 0 :(得分:0)

您可以检查用户代理。这让你了解它的浏览器类型(iphone,chrome等)

参考链接: https://www.whoishostingthis.com/tools/user-agent/

答案 1 :(得分:0)

你可以选中这样:

  if(/Android|webOS|iPhone|iPad|iPod|pocket|psp|kindle|avantgo|blazer|midori|Tablet|Palm|maemo|plucker|phone|BlackBerry|symbian|IEMobile|mobile|ZuneWP7|Windows Phone|Opera Mini/i.test(navigator.userAgent)) 
    {
     alert("App Open in Mobile");
    }
     else{
      alert("App Open in Other Source");
   }

答案 2 :(得分:0)

在Extjs中,您可以使用框架代码处理它而不使用js userAgent正则表达式:

if (Ext.os.is.Android || Ext.os.is.iOS) {
    // ... mobile
}else{
   // ... not mobile
}

You can read the documentation about Ext.os here