Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: UrlHelper throws MethodNotimplementedException with batching in webhost [215]

$
0
0
With the following batching code in webhost,

HttpConfiguration memoryConfig = new HttpConfiguration();
HttpServer memoryServer = new HttpServer(memoryConfig, GlobalConfiguration.DefaultHandler);
GlobalConfiguration.Configuration.MessageHandlers.Add(new BatchingMessageHandler(memoryServer));


we receive a MethodNotimplementedException while using UrlHelper.Route in the following action,

[ActionName("link"), HttpGet]
public string GetUrl()
{
return Url.Link("API Default", new { Controller = "batch", Action = "contacts" });
}


The issue here is that the routing is handled by HostedHttpRoute which expects the HttpRequestMessage to have a underlying asp.net HttpContextBase. But the request message that matches the route is a vanilla HttpRequestMessage created by the BatchingMessageHandler without any underlying HttpContextBase.


Fortunately, there is a workaround. Instead of reusing the routes from GlobalConfguration we need to create HttpRoute (not HostedHttpRoute) in the memory server of the BatchingHandler to make this scenario work like,

HttpConfiguration memoryConfig = new HttpConfiguration();
memoryConfig.MessageHandlers.Add(new SampleMemoryMessageHandler());
memoryConfig.Routes.MapHttpRoute(
name: "API Default",
routeTemplate: "app/api/{controller}/{action}",
defaults: new { controller = "Batch", action = RouteParameter.Optional }
);
HttpServer memoryServer = new HttpServer(memoryConfig);



Stack trace for the exception.

System.Web.dll!System.Web.HttpContextBase.Response.get() + 0x1e bytes
System.Web.dll!System.Web.Routing.RouteCollection.GetUrlWithApplicationPath(System.Web.Routing.RequestContext requestContext, string url) + 0x86 bytes
System.Web.dll!System.Web.Routing.RouteCollection.GetVirtualPath(System.Web.Routing.RequestContext requestContext, string name, System.Web.Routing.RouteValueDictionary values) + 0xd9 bytes
> System.Web.Http.WebHost.DLL!System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetVirtualPath(System.Net.Http.HttpRequestMessage request, string name, System.Collections.Generic.IDictionary<string,object> values) Line 114 + 0x22 bytes C#


Comments: Fixed: https://aspnetwebstack.codeplex.com/SourceControl/changeset/647f958b1ba7462f2da722fa5e807d5595d23c4b

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>