4

Closed

Make HostedHttpRoute public

description

Hi,

I'm the author of AttributeRouting, an open-source project that lets users specify routes using attributes in Mvc, Http.WebHost, and Http.SelfHost scenarios. When generating route for Http.WebHost scenarios, I need to register a custom Route object derived from System.Web.Http.WebHost.Routing.HostedHttpRoute. Currently this object is marked internal, making it impossible to simply hook into the underlying framework.

By contrast, both System.Web.Routing.Route (used by Mvc) and System.Web.Http.Routing.HttpRoute (used by Http.SelfHost) are public and allow me to hook directly into the underlying routing framework.

Cheers,

Tim McCall
Closed Feb 15 at 12:07 AM by HongmeiG
The real issue about registering a custom IHttpRoute has been fixed. Please see http://aspnetwebstack.codeplex.com/workitem/453, and you can view the actual fix at http://aspnetwebstack.codeplex.com/SourceControl/changeset/235544cf12a2

comments

HenrikN wrote Aug 4, 2012 at 10:49 PM

System.Web.Http.WebHost.Routing.HostedHttpRoute is just a thin wrapper around the MVC routing found in System.Web. It uses the same data as in the global routetable defined by System.Web.

Can you just register your routes with the MVC route table?

Thanks,

Henrik

mccalltd wrote Aug 4, 2012 at 11:48 PM

I could forgo deriving from it for sure. I just wanted to create a route
that wraps up the exact same thing the framework uses so I wouldn't miss
anything going forward. But I figured I'd ask for the simplest thing first.
:)

mccalltd wrote Aug 5, 2012 at 11:57 PM

So on further inspection, and having looked at RC, I noticed that System.Web.Http.RouteCollectionExtensions adds an HttpWebRoute to the route collection (I was mistaken in referencing HostedHttpRoute). AR used this class, the HttpWebRoute, for RC support, when it was marked public. But now, of course, I cannot simply piggyback on it because its accessibility has been changed to internal.

Simple enough to reverse engineer, but I am still curious about why it was changed from public to internal.

Thanks,

Tim

mccalltd wrote Aug 6, 2012 at 12:03 AM

You know, let me look into this more. I think I'm starting to get why the change from public to internal happened. Sorry for the fire drill. You can close the issue if you'd like, as it's evolving beyond my initial request.

Cheers

HongmeiG wrote Aug 11, 2012 at 12:04 AM

you actually need HttpWebRoute public, not the HostedHttpRoute.

mccalltd wrote Sep 5, 2012 at 7:55 AM

I've found a way around this and do not need anything to change in this regard. I had previously been registering ASP.NET Web API routes directly against the RouteCollection. That was fine in Beta and RC, but for RTM I need to use HttpRouteCollection instead. Internally, your bits will work the HttpWebRoute magic. So, again, I no longer need any changes regarding this issue. FYI.

HenrikN wrote Sep 5, 2012 at 1:47 PM

Good to know - thanks!

Henrik

mccalltd wrote Dec 17, 2012 at 1:08 PM

Please pardon my ignorance and confusion in regard to this issue....

Hongmei is right, I need HttpWebRoute. I was confused by all the Http wrappers in the WebHost assembly. My project uses custom routes to add some features on top of the base routing features via GetRouteData and GetVirtualPath. Currently there is no way to have my custom code run in web api web host scenarios :(. Internally, the web host bits create (or expect) HttpWebRoutes, and in the translation my custom route logic is tossed aside.

I see the issue is marked active and todo. Just wanted to clearly state that my head is more clear on the issue and I really need to be able to add HttpWebRoutes to the route table for web host scenarios.

Cheers!

TRoos wrote Jan 25 at 7:41 AM

Any ETA on this? Its badly needed..
Will you accept a pull request for it ?