Implementing a WAP Site Using ASP.NET-MVC

We are planning to implement a WAP site using ASP.NET-MVC.

Does anyone have any experience with this? Are there any Gotchas?

We will also be implementing a "standard" web site for browsers. Is it possible to have one set of models and controllers and just have separate views for each site?

+2


source to share


1 answer


In most cases, one set of models and controllers can be used. The way to do this is through the implementation of the following Theming / Templating mechanism. [Support support] [1] I put my solution on top of the Theming / Templating mechanism.

The main deviation from the article source is in the Global.asax.cs file where you need to add the following lines of code:

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");
            }
        }

      

I know I had to make a couple of code changes to make it MVC 1 compliant, but I can't remember the exact changes. Another major problem I encountered was output debugging. For this I used firefox with the extension ([User Agent Switcher] [2]), which I modified to add Accept Types to it.



For WAP2 / XHTML1.2, accept types are: text / html, application / vnd.wap.xhtml + xml, application / xhtml + xml, application / xml; q = 0.9, /; q = 0.8

Obviously you need your homepage and content page to be WML or XHTML1 compliant.

[1]: http://frugalcoder.us/post/2008/11/13/ASPNet-MVC-Theming.aspx Support Support

[2]: http://chrispederick.com/work/user-agent-switcher/ User Agent Switch

+3


source







All Articles