如果用户从平板电脑访问该站点,我正在尝试显示该站点的桌面版本。方法 contextCheck_WithDirectMethod 确实返回 false ,但移动版本仍显示在我的 ipad 上。任何有关如何解决此问题的帮助将不胜感激。
protected void Application_BeginRequest(object sender, EventArgs e)
{
System.Func<HttpContextBase, bool> contextCheckDelegate = contextCheck_WithDirectMethod;
DefaultDisplayMode mobileMode = new DefaultDisplayMode("mobile");
mobileMode.ContextCondition = contextCheckDelegate;
DisplayModeProvider.Instance.Modes.Add(mobileMode);
}
public bool contextCheck_WithDirectMethod(HttpContextBase objHttpContextBase)
{
bool isTablet = false;
string varBrowserAgent = objHttpContextBase.Request.UserAgent;
if (!string.IsNullOrEmpty(varBrowserAgent))
{
varBrowserAgent = varBrowserAgent.ToString().ToLower();
if (varBrowserAgent.Contains("ipad") || (varBrowserAgent.Contains("android") && !varBrowserAgent.Contains("mobile")))
{
isTablet = true;
objHttpContextBase.ClearOverriddenBrowser();
}
}
if (!isTablet)
{
if (objHttpContextBase.GetOverriddenBrowser().IsMobileDevice)
{
return true;
}
}
if (!string.IsNullOrEmpty(varBrowserAgent))
{
varBrowserAgent = varBrowserAgent.ToString().ToLower();
if (objHttpContextBase.Request.Browser.IsMobileDevice == true || varBrowserAgent.Contains("ipod") || varBrowserAgent.Contains("ipad")
|| varBrowserAgent.Contains("iphone") || varBrowserAgent.Contains("android") || varBrowserAgent.Contains("iemobile"))
{
if (isTablet)
return false;
else
return true;
}
}
return false;
}