문제

ASP.NET-MVC를 사용하여 WAP 사이트를 구현할 계획입니다.

이것에 대한 경험이 있습니까? gotchas가 있습니까?

또한 브라우저 용 "표준"웹 사이트를 구현할 것입니다. 단일 모델과 컨트롤러 세트를 가질 수 있고 각 사이트에 대해 별도의보기가있을 수 있습니까?

도움이 되었습니까?

해결책

대부분의 단일 모델과 컨트롤러 세트를 가질 수 있습니다. 다음과 같은 방법은 다음 테마/템플릿 엔진을 구현하는 것입니다. [테마 지원] [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 호환을 위해 몇 가지 코드를 변경해야한다는 것을 알고 있지만 정확한 변경 사항을 기억할 수 없습니다. 내가 가진 또 다른 주요 문제는 출력을 디버깅하는 것입니다. 이를 위해 나는 내장 ([사용자 에이전트 스위처] [2])와 함께 Firefox를 사용하여 접수 유형을 추가하도록 변경했습니다.

wap2/xhtml1.2의 경우 수락 유형은 다음과 같습니다. text/html, application/vnd.wap.xhtml+xml, application/xhtml+xml, application/xml; q = 0.9,/; q = 0.8

분명히 WML 또는 XHTML1.2를 준수하려면 MasterPage 및 콘텐츠 페이지가 필요합니다.

[1]: http://frugalcoder.us/post/2008/11/13/aspnet-mvc-theming.aspx 주제 지원

[2]: http://chrispederick.com/work/user-agent-switcher/ 사용자 에이전트 스위처

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top