0

誰でも助けることができますか?51Degrees の無料サービスを Lite バージョンではなくCloud API ( https://51degrees.com/compare-data-options ) で利用したい。

Global.asax を「タブレット」と「モバイル」の表示モードに設定して、使用できるようにしようとしています。

  • index.cshtml
  • index.tablet.cshtml
  • index.mobile.cshtml

以下は、51 Degrees を使用しない場合に機能します。51 Degrees Cloud API を global.asax と統合してタブレット/モバイルをフィルタリングする方法の例を誰かが持っていますか?

https://51degrees.com/Support/Documentation/APIs/Cloud-API/NET-Cloud

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Tablet")
            {
            ContextCondition = (ctx =>
            ctx.Request.UserAgent.IndexOf("iPad", StringComparison.OrdinalIgnoreCase) >= 0 ||
            ctx.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0  &&
            ctx.Request.UserAgent.IndexOf("Mobile", StringComparison.OrdinalIgnoreCase) <= 0
            )
            });

ありがとうトミー

4

1 に答える 1

1

リンクしたページの最初の C# の例を使用して、デスクトップ、スマートフォン、またはタブレット (およびその他のいくつか) の DeviceType の値を取得できます。何かのようなもの:

string json = webClient.DownloadString(String.Format(
  "https://cloud.51degrees.com/api/v1/{0}/match?user-agent={1}&values=DeviceType",
  yourLicenceKey, ctx.Request.UserAgent));

dynamic match = Newtonsoft.Json.Linq.JObject.Parse(json);

次に、タブレットの条件は次のようになります。

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Tablet")
            {
            ContextCondition = (ctx =>
                match.Values.DeviceType.IndexOf("Tablet", StringComparison) != -1))
            });

URL を使用して、DeviceType の可能な値を照会できます。

https://cloud.51degrees.com/api/v1/[you licence key]/values?propertyname=DeviceType

または、true または false を返す IsMobile、IsSmartPhone、IsTablet、および IsDesktop プロパティを使用します。

于 2016-08-25T12:11:57.273 に答える