I have seen how you can add custom routes to WebForms by using some code like this.
public class WebFormsRouteHandler : IRouteHandler
{
public string VirtualPath { get; set; }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// Compiles ASPX (if needed) and instantiates the web form
return (IHttpHandler) BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof (IHttpHandler));
}
}
I'm trying to get a similar thing to work but for web service files (TestService.asmx.) That previous method throws an exception because the page does not inherit from IHttpHandler. I've seen some other code that uses the WebServiceHandlerFactory like this
return new WebServiceHandlerFactory().GetHandler(context, requestType, url, pathTranslated);
That returns an IHttpHandler like I need but it needs an HttpContext passed in but the only thing I have access too as part of RequestContext is an HttpContextBase. From what I can tell I can't convert to an HttpContext from that.
Any ideas? Or maybe a different way to go about it? What I'm trying to accomplish is to control the urls for my web services through the normal routing system. An example is wanting TestService.asmx to come up as ExampleTestService/.