When I deploy a NET 6 blazor web app (server and client) into IIS but I got this error when I run it, http://blazorecommerceapi.findingsteve.net
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
When I run its api, http://blazorecommerceapi.findingsteve.net/api/product
But when I run it locally, it works as expected. I can run the blazor client page.
I can see the api data.
I am using Sqlite to persist the data and for the authentication, these are some codes in program.cs
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey =
new SymmetricSecurityKey(System.Text.Encoding.UTF8
.GetBytes(builder.Configuration.GetSection("AppSettings:Token").Value)),
ValidateIssuer = false,
ValidateAudience = false
};
});
app.UseAuthentication();
app.UseAuthorization();



