1

Getting this error and am in middlle of nowhere ---->

System.InvalidOperationException: No authentication handler is registered for the scheme 'You do not have permission to access this resource.'. The registered schemes are: Negotiate, Windows. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("You do not have permission to access this resource.",...)?

Program.cs:

using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.Authorization; builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme) .AddNegotiate(); builder.Services.AddAuthorization(options => { options.FallbackPolicy = options.DefaultPolicy; }); builder.Services.AddHttpContextAccessor(); builder.Services.AddAuthorization(options => { options.DefaultPolicy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting(); app.MapRazorPages(); app.MapControllers(); app.MapFallbackToFile("index.html"); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Run(); 
1
  • More suitable to post to Stack Overflow if you want others to review source code. Commented Jul 22, 2024 at 8:22

1 Answer 1

0

While you don't show your controller code, I'm guessing there's an innocent-looking return Forbid("You do not have permission to access this resource.") somewhere in it. Instead, use return StatusCode(403, "...").

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.