Answer the question
In order to leave comments, you need to log in
It is not possible to pass through the restriction on roles, although the user has everything that is needed. Maybe I don't notice something?
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<UserId>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequiredLength = 5;
options.Password.RequireUppercase = true;
options.Lockout.MaxFailedAccessAttempts = 5;
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = false;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddAuthorization(options => {
options.AddPolicy("AdministratorRole", policy =>
policy.RequireRole("Administrator"));
options.AddPolicy("UserRole", policy =>
policy.RequireRole("User"));
});
services.AddControllersWithViews();
services.AddRazorPages();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
[Authorize(Policy = "AdministratorRole")]
public class InGameModel : PageModel
{
public void OnGet() {
}
public void onPost() {
}
}
Answer the question
In order to leave comments, you need to log in
I found the answer. If anyone is interested, then catch the link https://stackoverflow.com/questions/29285406/refre...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question