Reputation: 63
I have a ASP.NET Core 3.1 Razor pages application which uses ADFS for authentication. I do not want a particular razor page to be authenticated. How do I achieve this? I know we can skip authorization on a folder/page using .AddRazorPagesOptions
but how do I skip authentication? Please see the code I have below:
app.UseStaticFiles();
app.UseAuthentication();
app.UseSession();
app.Use(
(next) =>
{
return async context =>
{
var user = context.User;
if (user == null || !user.Identities.Any(identity => identity.IsAuthenticated))
{
await context.ChallengeAsync();
}
else
{
//await app.SetAuthData(accessor);
await app.ConfigureEntitySession(accessor, env);
await next.Invoke(context);
}
};
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Upvotes: 0
Views: 926
Reputation: 505
Did you try
services.AddRazorPages()
.AddRazorPagesOptions(options =>
{
options.Conventions.AllowAnonymousToPage("/YourPage/...");
});
Upvotes: 4