I'm trying to write my own authentication middleware code.
In good old HttpModules, I could use "OnAuthenticateRequest" when a "Authorize" page was requested.
My middleware code is something like this:
public async Task Invoke(HttpContext context)
{
if (!context.User.Identity.IsAuthenticated)
{
}
}
... but that will also check IsAuthenticated on requests with [AllowAnonymous] attribute.
How can I from my middleware, check if the request has attribute [AllowAnonymous] or [Authorize]?
I need to be able to do something like...
public async Task Invoke(HttpContext context)
{
if (HasAuthorizeAttribute && !context.User.Identity.IsAuthenticated)
{
}
await _next.Invoke(context);
}
Thanks.