I have some kind of Mvc application in which I register routes with a pattern to a route handler, which gives out our custom httphandler to handle requests with such routes. I could get such requests executed when I run my application on IIS Express. I couldn't do the same when I try and host it on IIS. Could I be missing a handler mapping? If so, how can I map a handler to a route pattern?
public class SwaggerAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Swagger"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
....
....
context.Routes.Add(new Route(
"swagger",
null,
new RouteValueDictionary(new {constraint = new RouteDirectionConstraint(RouteDirection.IncomingRequest)}),
new RedirectRouteHandler("swagger/ui/index.html")));
context.Routes.Add(new Route(
"swagger/ui/{*path}",
null,
new RouteValueDictionary(new {constraint = new RouteDirectionConstraint(RouteDirection.IncomingRequest)}),
new SwaggerUiRouteHandler()));
}
}
public class SwaggerUiRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var swaggerUiConfig = SwaggerUiConfig.Instance;
var routePath = requestContext.RouteData.Values["path"].ToString();
var resourceAssembly = GetType().Assembly;
var resourceName = routePath;
InjectedResourceDescriptor injectedResourceDescriptor;
if (RequestIsForInjectedResource(routePath, swaggerUiConfig, out injectedResourceDescriptor))
{
resourceAssembly = injectedResourceDescriptor.ResourceAssembly;
resourceName = injectedResourceDescriptor.ResourceName;
}
if (resourceName == "index.html")
{
var response = requestContext.HttpContext.Response;
response.Filter = new SwaggerUiConfigFilter(response.Filter, swaggerUiConfig);
}
return new EmbeddedResourceHttpHandler(resourceAssembly, r => resourceName);
}
private bool RequestIsForInjectedResource(string routePath, SwaggerUiConfig swaggerUiConfig, out InjectedResourceDescriptor injectedResourceDescriptor)
{
injectedResourceDescriptor = swaggerUiConfig.CustomScripts
.Union(swaggerUiConfig.CustomStylesheets)
.FirstOrDefault(desc => desc.RelativePath == routePath);
return injectedResourceDescriptor != null;
}
}