I am trying to restrict access to a specific URL (/xyz) for anonymous users who do not possess a specific GUID cookie. To handle this, I created a middleware that assigns the cookie via HttpContext for users who do not have it and are not authenticated using Identity Framework.

To implement this functionality, I wanted to utilize authorization filters and policies, but I am unsure how to redirect anonymous users without the required cookie to a custom view, different than the one used by Identity Framework default schema.

I have come across information suggesting that I can use IAuthorizationMiddlewareResultHandler to solve my issue, but I am uncertain if this is the most appropriate solution. Additionally, I have seen others creating default cookie schemas for authentication, but I am unsure if these can be utilized for anonymous users, or how to assign them within a custom middleware.

1

There are 1 best solutions below

1
On

in the XyzController/Index action

if (noCookiePresent) return RedirectToAction("Index", "Home");