首页 文章

使用ASP.NET-MVC实现WAP站点

提问于
浏览
2

我们计划使用ASP.NET-MVC实现WAP站点 .

有没有人对此有任何体验?有没有陷阱?

我们还将为浏览器实施“标准”网站 . 是否可以拥有一组模型和控制器,并且每个站点都有单独的视图?

1 回答

  • 3

    大多数情况下可以使用一组模型和控制器 . 这样做的方法是通过实现以下主题/模板引擎 . [主题支持] [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,接受类型为:text / html,application / vnd.wap.xhtml xml,application / xhtml xml,application / 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-switcher/用户代理切换器

相关问题