Hi I am trying to create a custom authorize filter that will allow me to authorize requests coming from localhost automatically (which will be used for my tests).
I foun
You can create a middleware in which you can authorize requests coming from localhost automatically.
public class MyAuthorize
{
private readonly RequestDelegate _next;
public MyAuthorize(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
// authorize request source here.
await _next(httpContext);
}
}
Then create an extension method
public static class CustomMiddleware
{
public static IApplicationBuilder UseMyAuthorize(this IApplicationBuilder builder)
{
return builder.UseMiddleware();
}
}
and finally add it in startup Configure
method.
app.UseMyAuthorize();
Asp.Net Core did not have IsLoopback
property. Here is a work around for this
https://stackoverflow.com/a/41242493/2337983
You can also read more about Middleware here