views:

349

answers:

2

We plan on implementing a WAP site using ASP.NET-MVC.

Has anyone any experiance of this? Are there any Gotchas?

We will also be implementing a "standard" web site for browsers. Would it be possible to have a single set of Models and Controllers, and just have seperate views for each site?

+1  A: 

It is possible to have for the most part a single set of models and controllers. The way to do it will be via implementing the following Theming/Templating engine. [Theming Support][1] I piggy backed my solution on top of a Theming/Templating engine.

The major 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 compatible, but I can't remember the exact changes. The other major problem I had was debugging the output. For this I used firefox with an extension ([User Agent Switcher][2]) that I've changed to add Accept Types to it.

For WAP2/XHTML1.2 the 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 masterpage and content pages to adhere to WML or XHTML1.2

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

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

Schalk Versteeg
Thanks that helped alot
Shiraz Bhaiji
My pleasure :).
Schalk Versteeg
A: 

hand up! i have a question, coz the wap1.1 dosen't support javascript, so, of coz it dosen't support ajax. so, could i still develop wap1.1 with MVC in a general ajax-implentmented way?

thank you.

Grammy Leung
You should post this as a question rather than an answer to a question
Shiraz Bhaiji
Grammy Leung
thank you Shiraz!
Grammy Leung