Yeap, there we go
public class BlogRouteHandler : System.Web.Mvc.IRouteHandler
{
#region IRouteHandler Members
public System.Web.IHttpHandler GetHttpHandler(System.Web.Mvc.RequestContext requestContext)
{
BlogMvcHandler blogHandler=new BlogMvcHandler();
blogHandler.RequestContext = requestContext;
return blogHandler;
}
#endregion
}
public class BlogMvcHandler:System.Web.Mvc.MvcHandler
{
protected override void ProcessRequest(IHttpContext httpContext)
{
if (this.RequestContext == null)
throw new InvalidOperationException("No RequestContext");
Type controllerType = this.RequestContext.RouteData.Values["controllertype"] as Type;
IController controller = ControllerBuilder.Current.CreateController(this.RequestContext, controllerType);
ControllerContext controllerContext = new ControllerContext(base.RequestContext, controller);
controller.Execute(controllerContext);
}
}
and I set the route like
RouteTable.Routes.Add(new Route
{
Url = "Gallery/Index",
Defaults = new { controller="gallery",controllertype = typeof(GalleryController), action = "Index" },
RouteHandler = typeof(BlogRouteHandler)
});
A better way would be directly obtaining the controller type from the container but this works anyway.
Not intended to use in production.