ASP.Net Core - Policy and Cookie Authentication Reason on Forbidden Page
<p>I am using CookieAuthentication &amp; Policy to check the users and redirect to Account/Forbidden url when it fails... On the page, I want to display some details.. such as</p>

<ul>
<li>The page they tried to access</li>
<li>Reason of the Fail</li>
<li>And other debug info...</li>
</ul>

<p>There are 6 types of user levels in my app.
At the moment, it does redirect the users to Forbidden page when it fails to meet the UserRole... but I couldn't trace which page they were trying to access before the Forbidden occured...</p>

<p>ConfigureServices() in Startup.cs</p>

<pre><code>services.AddAuthorization(options =&gt;
{
    options.AddPolicy("AdminOnly", policy =&gt; policy.RequireRole("Admin"));
});
</code></pre>

<p>Configure() in Startup.cs</p>

<pre><code>app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookie",
    LoginPath = new PathString("/Account/Login/"),
    AccessDeniedPath = new PathString("/Account/Forbidden/"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});
</code></pre>

<p>My Controller:</p>

<pre><code>[Authorize(Policy = "AdminOnly")]
public class MyController : Controller
{
    ....
}
</code></pre>