c# - MVC4 站点 Mono 3.2.1 ubuntu 13.04 Nginx 移动 View

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

我已经设置了一个运行从 github 和 nginx 构建的 mono 3.2.1 的生产服务器。
一切正常,常规子域和我的单服务 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
(IE。)
https://github.com/mono/aspnetwebstack/blob/master/src/System.Web.WebPages/DisplayModeProvider.cs

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

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

非常感谢

戴夫

最佳答案

现在一切都很好。

我已经更改了将它们添加到 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
                                )
        });

关于c# - MVC4 站点 Mono 3.2.1 ubuntu 13.04 Nginx 移动 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19607407/

相关文章:

c# - 在涉及SslStream.AuthenticateAsClient()的客户端证书期间设置“Windows安全性”对话框所有者

c# - OutputCache 属性不适用于 .NET 7 API 端点

powershell - Invoke-WebRequest - json 中的特殊字符问题

c# - 尝试在没有模型出现 "tree may not contain dynamic operation"错误的情况下使用 DropDownListFor

c# - MVC4 - 如何将 EditorFor() 与来自数据库的动态表单数据一起使用

c# - 简单的 C# 事件参数问题

c# - 在 C# 中避免代码重复 - 通过使用泛型?

c++ - 在 Ubuntu 上使用 lighttpd 的 cgi

linux - lpr: 错误 - 未知选项 "V"

email - 查看 Ubuntu 上安装了哪个邮件服务器