Reputation: 35
I have an ASP.NET Core MVC application with Windows authentication enabled, and I want to use a basic interceptor to handle unauthenticated requests, but it is totally skipped because the Windows authentication mechanism blocks the request before entering the interceptor.
Do you know if there is a way to bypass this standard behaviour not blocking the request going in the interceptor pipeline?
Thanks in advance!
Upvotes: 0
Views: 393
Reputation: 4274
Use a middleware and declare it before the UseAuthorization
public class YourMiddleware
{
private readonly RequestDelegate _next;
public YourMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
Console.WriteLine("Before");
// Here you can decide if you want the next step of the pipeline or not, usually you want
await _next(context);
}
}
app.UseMiddleware<YourMiddleware>();
app.UseAuthorization();
Upvotes: -1