【问题标题】:Redirect to its own page重定向到自己的页面
【发布时间】:2012-08-13 15:17:08
【问题描述】:

我是 asp.net C# 的新手。

我正在创建一个专门针对移动用户的网站。

我想将页面重定向到用户移动版本及其平台。

我不想使用WURFL

还有这个http://51degrees.codeplex.com/

是否有任何其他可能的方式来为不同的移动用户创建页面?

例如 android(冰淇淋)和 android(姜饼)等的不同页面...

【问题讨论】:

  • 您可能想要评估useragent 字符串并使用它来控制重定向。
  • 您使用的是 ASP.NET Web Forms、ASP.NET Web Pages 还是 ASP.NET MVC(如果 MVC 是哪个版本?1、2、3 还是 4)?

标签: c# asp.net mobile-website


【解决方案1】:

像这样使用Request.UserAgent

if(Request.UserAgent.Contains("Android"))
{
    Response.Redirect("Andriod/MyPage.aspx");
}

版本检查也可以用同样的方式进行。所有流行的操作系统/浏览器的用户代理都可以在互联网上轻松获得。

【讨论】:

    【解决方案2】:

    您可以使用 JavaScript 导航器。像这样的:

    p = navigator.platform;
    
    // Detects if it is an iOS device
    if( p === 'iPad' || p === 'iPhone' || p === 'iPod' ){
        //iOS = true;
        //Redirect
    }
    
    // Detects if it is an Android device
    if(p.indexOf("android")>=0);
        //Android= true;
        //Redirect
    }
    

    var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false );
    if(iOS)
        //Redicret
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多