Seems like this should be a straightforward question, but I've been unable to find a solution via Google.
It seems pretty standard that in ASP.NET Core, IHttpHandler
implementors are replaced by middleware classes. One nicety of the old system was that you could set up an HTTP handler to respond to a route, specified in the web.config.
So, for instance, if my IHttpHandler
implementor was named FooHandler
, web.config would contain something like:
<location path="foo">
<system.webServer>
<handlers>
<add name="FooHandler" path="*" verb="*" type="FooCompany.FooProduct.FooHandler, FooCompany.FooProduct"/>
</handlers>
</system.webServer>
</location>
Is there a one-to-one replacement for routing like this in ASP.NET Core? How do I do this?
Edit: The new middleware class might look something like:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
namespace FooCompany.FooProduct.Middleware
{
public class FooMiddleware
{
private readonly RequestDelegate _next;
public FooMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
context.Response.StatusCode = 200;
await context.Response.WriteAsync("OK");
await _next.Invoke(context);
}
}
public static class FooMiddlewareExtensions
{
public static IApplicationBuilder UseFoo(this IApplicationBuilder builder)
{
return builder.UseMiddleware<FooMiddleware>();
}
}
}