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…
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>
<html>
<head>
<title></title>
@Windows.JumpListTask("Test", "~/", "fav.ico")
</head>
<body>
</body>
</html>
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?
2 Comments
Tommy Carlier said
September 15, 2010
Checking for the exact version number is not a good idea. What happens when IE10 is released? And why shouldn't you render the meta-tag for other browsers? What if other browsers want to implement this feature too?
Erik said
September 15, 2010
Fair enough on the version number (easy fix...this was just something I did over lunch and it works now). If we pulled this in as an official helper that would be cleaned up.
Because these will be easy to update (again, if we pull this in as an official helper we will keep them up to date with new releases) and you shouldn't build stuff off of guesses. When other browsers support it, then we would update it.
If you go to Twitter right now in any browser other than IE 9 you'll notice no new meta tags. I'm sure if other browsers support them, they'll start rendering them in other browsers (just like this helper would).