4,815 questions
You need to configure Authentication middleware in the Startup.cs
// Inside ConfigureServices method
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
services.AddAuthorization(options =>
{
options.AddPolicy("AdminOnly", policy =>
policy.RequireRole("Admin"));
});
and next in the authentication callback, redirect to where you prefer (e.g. OnAuthenticated or OnTokenValidated)
// Inside the authentication callback method
var user = context.Principal;
if (user.IsInRole("Admin"))
{
context.Response.Redirect("/admin/index");
}
else
{
context.Response.Redirect("/index");
}