我们计划实现使用ASP.NET MVC的一个WAP网站。

有任何人的任何这的experiance?是否有任何陷阱?

我们也将实施“标准”网站的浏览器。有没有可能有一组模型和控制器的,只是为每个网站单独的看法?

有帮助吗?

解决方案

是可能的有大部分的单组模型和控制器。 做到这一点的方式将通过实施以下主题化/模板引擎。 [主题化支持] [1] 我捎带上的主题化/模板发动机的顶部我的溶液。

从制品源的主要偏差在需要添加以下代码行的Global.asax.cs文件:

protected void Application_BeginRequest(Object Sender, EventArgs e)
{
  SetTheme();
}
//this will set the responses Content Type to xhtml and is necessary as C# sends the WML response header
protected void Application_PreSendRequestHeaders(Object Sender, EventArgs e)
{
  if (this.Context.Items["themeName"].ToString() == "xhtml")
  {
    this.Context.Response.ContentType = "application/vnd.wap.xhtml+xml";
  }
}

private void SetTheme()
{
  //set the content type for the ViewEngine to utilize. 

            HttpContext context = this.Context;
            MobileCapabilities currentCapabilities = (MobileCapabilities)context.Request.Browser;
            String prefMime = currentCapabilities.PreferredRenderingMime;

            string accept = context.Request.ServerVariables["HTTP_ACCEPT"];
            context.Items.Remove("theme");
            context.Items.Remove("themeName");

            if (accept.Contains("application/vnd.wap.xhtml+xml"))
            {
                context.Items.Add("themeName", "xhtml");
            }
            else if (prefMime == "text/vnd.wap.wml")
            {
                context.Items.Add("themeName", "WAP");
            }
            if (!context.Items.Contains("themeName"))
            {
                context.Items.Add("themeName", "Default");
            }
        }

我知道我不得不作出了几个代码更改,使其MVC 1相兼容,但我不记得确切的变化。 其他主要的问题我已经被调试输出。为此,我使用的Firefox的扩展名([用户代理切换] [2]),我已经改变了添加接受的类型吧。

有关WAP2 / XHTML1.2的Accept类型有:text / html的,应用/ vnd.wap.xhtml + xml的,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / ; q = 0.8

显然,你需要你的母版页和内容页坚持以WML或XHTML1.2

[1]: http://frugalcoder.us /post/2008/11/13/ASPNet-MVC-Theming.aspx 主题化支持

[2]: http://chrispederick.com/work/user-agent-切换器/ 用户代理切换

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top