IE 9 Windows Jump List ASP.NET Web Pages Helper

I’m sure you’ve all heard today about the beta release of IE 9.  It’s looking pretty good!  Did you see that you can integrate with the Windows Jump List now?  Neato!  Neowin has a write up on the meta tags you need to have to integrate with Windows.  Over lunch I wrote a quick helper in ASP.NET Web Pages (install WebMatrix via WebPI here) that you can just drop into your App_Code folder…

Code Snippet
using System;
using System.Web;
using System.Web.Mvc;
using Microsoft.WebPages.Helpers;

public static class Windows {
    public static IHtmlString JumpListTask(string name, string actionUrl, string iconUrl) {
        HttpContext httpContext = HttpContext.Current;
        if (httpContext.Request.Browser.Browser == "IE" && httpContext.Request.Browser.Version.StartsWith("9")) {
            if (string.IsNullOrWhiteSpace(name)) {
                throw new ArgumentNullException("name");
            if (string.IsNullOrWhiteSpace(actionUrl)) {
                throw new ArgumentNullException("actionUrl");

            if (string.IsNullOrWhiteSpace(iconUrl)) {
                throw new ArgumentNullException("iconUrl");

            if (!(actionUrl.StartsWith("http://") || actionUrl.StartsWith("https://"))) {
                string hostUrl = httpContext.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
                actionUrl = hostUrl + VirtualPathUtility.ToAbsolute(actionUrl);

            TagBuilder html = new TagBuilder("meta");
            html.MergeAttribute("name", "msapplication-task");
            html.MergeAttribute("content", string.Format("name={0}; action-uri={1}; icon-uri={2}", name, actionUrl, iconUrl));

            return new HtmlString(html.ToString(TagRenderMode.SelfClosing));
        return new HtmlString("");

And then call it in your page…

<!DOCTYPE html>
        @Windows.JumpListTask("Test", "~/", "fav.ico")

Not much to it, but hopefully some of you will find it handy.  Note: it does not render anything in browsers other than IE 9.  Maybe we can clean this up and put it in the next release of ASP.NET Web Pages.  :)  What do you think?  Do you have other ideas for helpers in ASP.NET Web Pages?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s