locked
ASP.NET web pages or mobile forms? RRS feed

  • Question

  • User-1179442337 posted

    just wanted to present sum code that will maby help sum1 understand the differences between wap 1.1(wml) and wap 2.0(XHTML) and normal (HTML)

    errr, laymens terms-  difference between web applications, and mobile web applications. i did this in Visual Web Dev 2005 Express Edition.

    compile the code, copy it to your server, then view it from IE or mobile phone or any wap browser (klondike,m3gate,openwave,etc)

     

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Web.Mobile" %>
    <script class=st runat=">
        
        public void Page_Load(Object sender, EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Charset = "UTF-8";
            Response.Expires = 0;
    
            MobileCapabilities currentCapabilities
            = (MobileCapabilities)Request.Browser;
            String prefMime = currentCapabilities.PreferredRenderingMime;
    
            string page_title = "Capabilities";
    
            string accept = Request.ServerVariables["HTTP_ACCEPT"];
            string mime = "";
    
            if (prefMime == "text/html")
            {
                mime = "text/html";
            }
            else if (prefMime == "text/vnd.wap.wml")
            {
                mime = "text/vnd.wap.wml";
            }
    
            if (accept.Contains("application/vnd.wap.xhtml+xml"))
            {
                mime = "text/html";
            }
    
    
            if (mime == "text/html")
            {
                Response.ContentType = "text/html";
                Response.Write(HTML_head(page_title));
            }
            else if (mime == "text/vnd.wap.wml")
            {
                Response.ContentType = "text/vnd.wap.wml";
                Response.Write(WML_head(page_title));
    
            }
    
        }
        
        
        private string HTML_head(string page_title)
        {
             string page_head = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
             "&lt;!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"" +
             "\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">" +
             "&lt;html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">" +
             "&lt;head><title>" + page_title + "&lt;/title>" +
             "&lt;link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />" +
             "&lt;/head><body><div>" + HTML_PageContent() + "&lt;/div></body></html>";
             return page_head;
        }
    
        private string WML_head(string page_title)
        {
            string page_head = "&lt;?xml version='1.0'?>" +
            "&lt;!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'" +
            "'http://www.wapforum.org/DTD/wml_1.1.xml'><wml><head>" +
            "&lt;meta http-equiv=\"Cache-Control\" content=\"max-age=0\" /></head>" +
            "&lt;card title=\"" + page_title + "\"&gt;<p>" + WML_PageContent() +
            "&lt;/p></card></wml>";
            return page_head;
        }
    
    
        private string HTML_PageContent()
        {
            string HTML_content = "&#91;<b>Html supported browser]</b>" +
                Capabilities();
            return HTML_content;
        }
        
        
    
        private string WML_PageContent()
    {
        string WMLcontent = "&#91;<b>WML 1.1 browser]</b>" +
            Capabilities();
        return WMLcontent;
    }
        
        
        
                private string Capabilities()
            {
                MobileCapabilities currentCapabilities
                = (MobileCapabilities)Request.Browser;
                String prefMime = currentCapabilities.PreferredRenderingMime;
    
                string capabil = "&lt;br/>Screen Width (chars): " + currentCapabilities.ScreenCharactersWidth.ToString() +
                "&lt;br/>Screen Height (chars): " + currentCapabilities.ScreenCharactersHeight.ToString() +
                "&lt;br/>Screen Pixels Width (pixels): " + currentCapabilities.ScreenPixelsWidth.ToString() +
                "&lt;br/>Screen Pixels Height (pixels): " + currentCapabilities.ScreenPixelsHeight.ToString() +
                "&lt;br/>Platform: " + currentCapabilities.Platform.ToString() +
                "&lt;br/>Mobile Manufacturer: " + currentCapabilities.MobileDeviceManufacturer +
                "&lt;br/>Supports body color: " + currentCapabilities.SupportsBodyColor +
                "&lt;br/>Supports JavaScript: " + currentCapabilities.JavaScript +
                "&lt;br/>IsMobileDevice: " + currentCapabilities.IsMobileDevice +
                "&lt;br/>Id: " + currentCapabilities.Id +
                "&lt;br/>GateWayVersion: " + currentCapabilities.GatewayVersion +
                "&lt;br/>IsWebCrawler: " + currentCapabilities.Crawler +
                "&lt;br/>Supports Cookies: " + currentCapabilities.Cookies +
                "&lt;br/>Supports BackGroundSounds: " + currentCapabilities.BackgroundSounds +
                "&lt;br/>Supports ActiveXControls: " + currentCapabilities.ActiveXControls +
                "&lt;br/>NumberOf SoftKeys: " + currentCapabilities.NumberOfSoftkeys +
                "&lt;br/>MobileDeviceModel: " + currentCapabilities.MobileDeviceModel +
                "&lt;br/>Page Content-Type: " + Response.ContentType.ToString();
                   
                    return capabil;
            }
    
    </script>
     
    Saturday, March 17, 2007 2:30 AM

All replies

  • User-1179442337 posted

     weird, it cut off the top portion of my script, but the top 3 lines should read:

    <%@ Page Language="C#" %>

    <%@ Import Namespace="System.Web.Mobile" %>

    <script runat="server">

     

    and finally at the bottom should be the ending script tag:

    </script>


    <%@ Import Namespace="System.Web.Mobile" %>
    Saturday, March 17, 2007 4:22 AM
  • User-1266225229 posted

    Hi jamsweb, you helped with an issue re PrefferedRendingMime recently; http://forums.asp.net/thread/1621309.aspx thanks again.

    My objective is very simple to serve correct content to moble devices, easier said then done! This script could be what im looking for.

    I want to filter all Xhtml browsers web and mobile that receive CSS and those WAP browsers that recieve wml1.1 dtd

    I compiled the above code with heading

    <%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" %>
    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
    <%@ Import Namespace="System.Web.Mobile" %>

    and changed; string capabil = (to capabilties) and return capabil also.

    There is a compilation error however :(  hoping you can help Paul 

    CS0117: 'string' does not contain a definition for 'Contains'

    Line 32:         if (accept.Contains("application/vnd.wap.xhtml+xml"))

    Sunday, March 18, 2007 5:43 AM
  • User-1179442337 posted

    i will try to paste the right code in here from top to bottom:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Web.Mobile" %>
    <script runat="server">
       
     
        public void Page_Load(Object sender, EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Charset = "UTF-8";
            Response.Expires = 0;

            MobileCapabilities currentCapabilities
            = (MobileCapabilities)Request.Browser;
            String prefMime = currentCapabilities.PreferredRenderingMime;
           
            string page_title = "Capabilities";
           
            string accept = Request.ServerVariables["HTTP_ACCEPT"];
            string mime = "";

            if (prefMime == "text/html")
            {
                mime = "text/html";
            }
            else if (prefMime == "text/vnd.wap.wml")
            {
                mime = "text/vnd.wap.wml";
            }
           
            if (accept.Contains("application/vnd.wap.xhtml+xml"))
            {
                mime = "text/html";
            }


            if (mime == "text/html")
            {
                Response.ContentType = "text/html";
                Response.Write(HTML_head(page_title));
            }
            else if (mime == "text/vnd.wap.wml")
            {
                Response.ContentType = "text/vnd.wap.wml";
                Response.Write(WML_head(page_title));

            }

        }
       
       
        private string HTML_head(string page_title)
        {
             string page_head = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
             "&lt;!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"" +
             "\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">" +
             "&lt;html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">" +
             "&lt;head><title>" + page_title + "&lt;/title>" +
             "&lt;link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />" +
             "&lt;/head><body><div>" + HTML_PageContent() + "&lt;/div></body></html>";
             return page_head;
        }

        private string WML_head(string page_title)
        {
            string page_head = "&lt;?xml version='1.0'?>" +
            "&lt;!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'" +
            "'http://www.wapforum.org/DTD/wml_1.1.xml'><wml><head>" +
            "&lt;meta http-equiv=\"Cache-Control\" content=\"max-age=0\" /></head>" +
            "&lt;card title=\"" + page_title + "\"&gt;<p>" + WML_PageContent() +
            "&lt;/p></card></wml>";
            return page_head;
        }


        private string HTML_PageContent()
        {
            string HTML_content = "&#91;<b>Html supported browser]</b>" +
                Capabilities();
            return HTML_content;
        }
        
       

        private string WML_PageContent()
    {
        string WMLcontent = "&#91;<b>WML 1.1 browser]</b>" +
            Capabilities();
        return WMLcontent;
    }
       
       
       
                private string Capabilities()
            {
                MobileCapabilities currentCapabilities
                = (MobileCapabilities)Request.Browser;
                String prefMime = currentCapabilities.PreferredRenderingMime;

                string capabil = "&lt;br/>Screen Width (chars): " + currentCapabilities.ScreenCharactersWidth.ToString() +
                "&lt;br/>Screen Height (chars): " + currentCapabilities.ScreenCharactersHeight.ToString() +
                "&lt;br/>Screen Pixels Width (pixels): " + currentCapabilities.ScreenPixelsWidth.ToString() +
                "&lt;br/>Screen Pixels Height (pixels): " + currentCapabilities.ScreenPixelsHeight.ToString() +
                "&lt;br/>Platform: " + currentCapabilities.Platform.ToString() +
                "&lt;br/>Mobile Manufacturer: " + currentCapabilities.MobileDeviceManufacturer +
                "&lt;br/>Supports body color: " + currentCapabilities.SupportsBodyColor +
                "&lt;br/>Supports JavaScript: " + currentCapabilities.JavaScript +
                "&lt;br/>IsMobileDevice: " + currentCapabilities.IsMobileDevice +
                "&lt;br/>Id: " + currentCapabilities.Id +
                "&lt;br/>GateWayVersion: " + currentCapabilities.GatewayVersion +
                "&lt;br/>IsWebCrawler: " + currentCapabilities.Crawler +
                "&lt;br/>Supports Cookies: " + currentCapabilities.Cookies +
                "&lt;br/>Supports BackGroundSounds: " + currentCapabilities.BackgroundSounds +
                "&lt;br/>Supports ActiveXControls: " + currentCapabilities.ActiveXControls +
                "&lt;br/>NumberOf SoftKeys: " + currentCapabilities.NumberOfSoftkeys +
                "&lt;br/>MobileDeviceModel: " + currentCapabilities.MobileDeviceModel +
                "&lt;br/>Page Content-Type: " + Response.ContentType.ToString();
                  
                    return capabil;
            }

    </script>

    Sunday, March 18, 2007 6:19 PM
  • User-1179442337 posted

    ok the copy and paste thing not working out for me lol, the above code is correct except replace &lt; with <

    (the left angle bracket)

     

    Sunday, March 18, 2007 6:29 PM
  • User-1179442337 posted

      plkilroy, are you using Visual Web Developer 2005 express edition and .net 2.0?

    'Contains' lives in class 'String' which is in namespace 'System'

     

    Sunday, March 18, 2007 6:56 PM
  • User-1266225229 posted

    Hi jansweb, yes I use VWD 05 express and .net2.0 for dev. Did your system compile this script, with those changes i still return CS0117: 'string' does not contain a definition for 'Contains'

    cheers Paul

    Sunday, March 18, 2007 9:04 PM
  • User-1179442337 posted
    yes it compiles fine on my system. maby for sum reason on yours, you have to Import Namespace 'System'?
    Sunday, March 18, 2007 10:04 PM
  • User-1266225229 posted

     Hi jansweb, i checked my system and see it running 

    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

    I had updated system to .net framework 2, this doesnt appear to be running! so I guess I have to sort this out,

    However I tested this script remotely, and it is picking up text/html correctly, but using Nokia 7210 sdk for checking WML the dtd wont serve.

     private string WML_head(string page_title)
        {
            string page_head = <?xml version='1.0'?>" +
            <!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'" +
            "'http://www.wapforum.org/DTD/wml_1.1.xml'><wml><head>" +
            <meta http-equiv=\"Cache-Control\" content=\"max-age=0\" /></head>" +
            <card title=\"" + page_title + "\"&gt;<p>" + WML_PageContent() +
            </p></card></wml>";
            return page_head;
        }

     

    Much thanks for your time as this is a major concern for anyone rendering content to mobile devices, cheers Paul

    Sunday, March 18, 2007 10:37 PM
  • User-1179442337 posted

    ok i had to dig out my nokia 7210 to fix this, it was 2 small errors in the WML_head(string page_title)

    first there needs to be a space right after EN

           "<!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'" +

    and the second problem was when i pasted the code to this forum it changed a angle bracket to:  &gt;

    <card title=\"" + page_title + "\"&gt;<p>" + WML_PageContent() +

    and i also chose to use double quotes in the doctype this time around so here is the new method:

     

     

    private string WML_head(string page_title)

    {

    string page_head = "<?xml version=\"1.0\"?>" +

    "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" " +

    "\"http://www.wapforum.org/DTD/wml_1.1.xml\"><wml><head>" +

    "<meta http-equiv=\"Cache-Control\" content=\"max-age=0\" /></head>" +

    "<card title=\"" + page_title + "\"><p>" + WML_PageContent() +

    "</p></card></wml>";

    return page_head;

    }

     

    Monday, March 19, 2007 3:37 AM
  • User-1179442337 posted

    make sure the space is in there, otherwise when the browser recieves the response, it will show as one long like this:

    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml">

    and it should be like this:

    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

    Monday, March 19, 2007 3:43 AM
  • User-1266225229 posted

    THANKS!!! jamsweb, big big help, now I have something I can test with, cheers Paul

    Monday, March 19, 2007 10:26 PM
  • User-2100006091 posted

    Thank you for sharing your code. But I have a question with regards to mime types. How do we deal or handle mime text/vnd.wap.wml errors?

    Saturday, December 4, 2010 5:52 PM
  • User-525215917 posted

    To get all mobile devices supported normally you need more than one view for same thing. Forget ASP.NET Forms and mobile forms - they doesn't fit here because they doesn't provide flexibility you need. The code example you pasted here is practically an awful hack that should never go to production. 

    Take ASP.NET MVC framework and you can write normal system. You can make controllers detect devices (use WURFL by example) and render different views based on device settings. You will move faster than building on hack another for ASP.NET Forms or mobile forms.

    Been there, done that. 

    Saturday, December 4, 2010 5:59 PM
  • User-1266225229 posted

    My part of this thread is over 3 years old! and yes things have moved on in mobile dev. I recommend 51degrees.mobi mobile detect API and also dotmobi DeviceAtlas both have .Net releases. Hope someone finds usefull! P

    Tuesday, December 7, 2010 7:41 PM