if (Request.Browser.IsMobileDevice)
{
Response.Redirect("/mobile/Login.htm");`
}
Run Code Online (Sandbox Code Playgroud)
为了检测移动设备但同时检测到移动设备上的平板电脑,我需要检查是否有平板电脑或功能检查设备屏幕大小的功能.
感谢"我的工作,我使用ScreenPixelsWidth和ScreenPixelsHeight这是代码,如果有任何需要它
int wight = Request.Browser.ScreenPixelsWidth;
int height = Request.Browser.ScreenPixelsHeight;
if (Request.Browser.IsMobileDevice && wight < 720 && height<1280)
{
Response.Redirect("/mobile/Login.htm");
}
Run Code Online (Sandbox Code Playgroud)
小智 21
我有一个类似的问题,并尝试使用:HttpContext.Request.Browser.ScreenPixelsWidth
然而,无论设备(iphone或ipad)如何,它总是返回640像素的值.我通过创建静态方法来检查用户代理字符串来解决此问题.
public class DeviceHelper
{
public static bool IsTablet(string userAgent, bool isMobile)
{
Regex r = new Regex("ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle|nexus");
bool isTablet = r.IsMatch(userAgent) && isMobile;
return isTablet;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中:
if(DeviceHelper.IsTablet(Request.UserAgent, Request.Browser.IsMobileDevice))
return Redirect("..."); // redirect to tablet url
Run Code Online (Sandbox Code Playgroud)
您可以使用ScreenPixelsWidth和ScreenPixelsHeight(http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilities.aspx),您可以定义一个阈值,您可以在其中考虑常规版本或移动版本应该是渲染.
还有很多方法可以解决这个问题,但由于您已经在使用HttpBrowserCapabilities类,因此您也可以使用这两个属性.
归档时间: |
|
查看次数: |
16392 次 |
最近记录: |