Add support for the iPhone to your ASP.NET pages

Thursday, December 20 2007

So, you realized that many people get to your blog using the iPhone and you want to provide a better interface for people using the iPhone, even knowing the iPhone has the best browser compared to other mobile devices, will be nice to be able to ready the posts without other frames around, just the posts.

To accomplish that I wrote a Http Handler for Community Server, of course you can use it for your own blog even if you are not using CS 2007.

Why a http handler? Well the fastest way to get that working as I can inspect the request and redirect it to the rss feed bypassing the html.

On the request we can do :

public class iPhoneSupport : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.UserAgent.ToUpper().IndexOf("IPHONE") > -1)
            {
                context.Response.Redirect(context.Request.Url.ToString().Replace("default.aspx", "rss.aspx"));
            }
        }

        #endregion
    }

 

So when the user requests the main page for the blog, you can redirect them to the RSS page for better formatting. Will make the life of the iPhone user much easier.

Also you can use Server.Transfer instead of Response.Redirect if you want to hide the URL, but I would recommend to use Response.Redirect.

To register the Http Handler on Community Server:

<httpHandlers>

<add verb="*"

         path="~blog/al/default.aspx"

         type="BlogCalendar.iPhoneSupport" />

</httpHandlers>

Remember the iPhone user loves reading blogs, let's make it easier for them/us.

Cheers

Al

Comments

I Organize » Blog Archive » Add support for the iPhone to your ASP.NET pages said on 12.21.2007 at 1:08 AM

Pingback from  I Organize  &raquo; Blog Archive   &raquo; Add support for the iPhone to your ASP.NET pages


IPhone » Add support for the iPhone to your ASP.NET pages said on 12.21.2007 at 1:45 AM

Pingback from  IPhone &raquo; Add support for the iPhone to your ASP.NET pages


Iphone: Apple Iphone Reviews, Accessories & Gadgets » Add support for the iPhone to your ASP.NET pages said on 12.21.2007 at 3:38 AM

Pingback from  Iphone: Apple Iphone Reviews, Accessories &#038; Gadgets &raquo; Add support for the iPhone to your ASP.NET pages


Joe Levi said on 12.21.2007 at 5:24 PM

Isn't the whole selling point behind the iPhone the fact that all the websites in the entire world are right there without any changes at all?!

- www.JoeLevi.com


Hosam Kamel said on 12.22.2007 at 9:04 AM

a good article explains the implementation of an ASP.NET handler to add support to iPhone in the ASP


Scott Hanselman's Computer Zen said on 6.09.2008 at 7:34 PM


eric ramseur said on 7.25.2008 at 6:37 PM

Might want to add ipod to that mix as that will allow for the ipod touch as well as the iphone.