【问题标题】:MVC4 site Mono 3.2.1 ubuntu 13.04 Nginx Mobile ViewsMVC4 站点 Mono 3.2.1 ubuntu 13.04 Nginx 移动视图
【发布时间】:2013-10-26 13:40:38
【问题描述】:

我已经设置了一个运行从 github 和 nginx 构建的 mono 3.2.1 的生产服务器。 一切正常,常规子域和我的monoserved mvc4 站点。 我也切换到 unix 套接字而不是 tcp,因为我注意到 ram 使用方面的一些奇怪行为。

到目前为止 - 我只使用了我在具有相同配置的 windows VPS 上使用的系统资源的 10%,所以 linux 托管的 mvc 就像第一次发现切片面包:D

但是,我在尝试以下操作时收到 NotImplementedException 错误:

在我的 Global.asax.cs 文件中,在 Application_Start() 下的捆绑设置之后 我正在注册或至少尝试注册检查以查看它是否是移动设备,从而为我的 Index.Mobile.cshtml 提供服务

像这样

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iphone")
        {
            ContextCondition = Context =>
                            Context.Request.Browser["HardwareModel"] == "iPhone"
        });

        DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("android")
        {
            ContextCondition = Context =>
                            Context.Request.Browser["PlatformName"] == "Android"
        });

        DisplayModeProvider.Instance.Modes.Insert(2, new DefaultDisplayMode("mobile")
        {
            ContextCondition = Context =>
                            Context.Request.Browser["IsMobile"] == "True"
        });

    }

据我发现,在单声道的aspnetwebstack中,有DisplayModeProvider (即)

https://github.com/mono/aspnetwebstack/blob/master/src/System.Web.WebPages/DisplayModeProvider.cs

但是如果我的 Global.asax.cs 中有这些行,当我尝试加载页面(在我的 webconfig 中)时,我会收到错误消息,指出它没有实现

谁能指出我正确的方向,因为我需要这个网站为手机提供不同的页面:)

非常感谢

戴夫

【问题讨论】:

    标签: c# asp.net-mvc-4 ubuntu nginx mono


    【解决方案1】:

    现在一切都好。

    我更改了将它们添加到 DisplayModeProvider 的方式。

    如果我这样做,它会很好地工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 2013-06-08
      • 2016-02-25
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      相关资源
      最近更新 更多