I'm a huge fan of ASP.NET Routing. It gained popularity as the part of ASP.NET MVC which channels requests for a given URL to the right controller action. In a wise move, Microsoft moved the routing infrastructure out of ASP.NET MVC and into its own assembly with the release of .NET 3.5 SP1.
With ASP.NET Routing you can construct search engine optimized and human friendly URLs such as these:
This is well documented in the ASP.NET MVC world running on your server - you can't get anything done without it in MVC. But what about Windows Azure? What if you don't want ASP.NET MVC? What if you're a traditional type of person and want all the goodness that comes with what is now called ASP.NET WebForms (aka "normal ASP.NET")?
In this brief post, I'll cover how to use ASP.NET routing and ASP.NET WebForms in Azure. The sample project can be downloaded if you want to follow along. Phil Haack has written a good post on using routing alongside ASP.NET WebForms so I won't cover too much background information.
The short answer is that it doesn't. If you get routing working for IIS 7 in your web app, you can effectively deploy it to Azure. But the steps always felt convoluted to me when reading others' write-ups on this. So let's run through converting a Windows Azure Web Role (essentially a "stock" ASP.NET WebForms app) to use routing in Azure.
First you'll need the Azure SDK and Visual Studio tools:
internal class CustomRoute : IRouteHandler { public CustomRoute(string virtualPath) { VirtualPath = virtualPath; } public string VirtualPath { get; private set; } public IHttpHandler GetHttpHandler(RequestContext requestContext) { foreach ( var aux in requestContext.RouteData.Values ) { HttpContext.Current.Items[aux.Key] = aux.Value; } return BuildManager.CreateInstanceFromVirtualPath( VirtualPath, typeof( Page ) ) as IHttpHandler; } }
protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.Add( "ShowName", new Route( "naming/show/{name}", new CustomRoute( "~/ShowName.aspx" ) ) ); RouteTable.Routes.Add( "CreateAccount", new Route( "account/begin", new CustomRoute( "~/Account.aspx" ) ) ); RouteTable.Routes.Add( "Home", new Route( "home", new CustomRoute( "~/Default.aspx" ) ) ); }
class Iis7RoutingHandler : UrlRoutingHandler { protected override void VerifyAndProcessRequest( IHttpHandler httpHandler, HttpContextBase httpContext) { } }
...
LabelName.Text = (string)HttpContext.Current.Items["name"];
Download the source and try it for yourself: AzureRoutingSample.zip (136 KB)
Posted in Articles | ASP.NET | Azure | DevelopMentor | web2.0 |Comments [0]
A blog by Michael Kennedy
Speaking Events
About: Michael is an instructor for DevelopMentor, a .NET enthusiast, an agile pioneer, an entrepreneur, a father of three girls, a husband, a student, and a teacher.
Explore Related Content
Concepts >> azure - Workflow - RESTful - Unit Testing - web - WCF - ASP.Net - MVC - LINQ
Tools >> Visual Studio ClickOnce IIS
Type >> Screencast - Tools - Article - How To - Course
@dm_the_company @mkennedy @andrewclymer @bmaso @danamiga @georgeshep @isidore_us @jason_diamond @markblomsma @marksm @mauricedb @pierrenallet @richardblewett @tonysneed @wallacekelly
Sign In