由于授权属性,成功登录后,我无法路由Home / Index。
结果:https://localhost:44339/Account/Login?ReturnUrl=%2F
我该如何解决
等待您的答案
// Startup.cs
public void ConfigureServices(IServiceCollection服务)
{
services.AddControllersWithViews();
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration["DefaultConnection"]));
services.AddIdentity<User,IdentityRole>()
// services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc(op=> { op.EnableEndpointRouting = false;}).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/account/Login";
// options.LogoutPath = $"/Identity/account/Logout";
options.accessDeniedPath = $"/account/accessDenied";
});
services.AddLogging(config =>
{
config.AddConsole();
config.AddDebug();
//etc
});
services.AddTransient<ClaimsPrincipal>(
s => s.GetService<IHttpContextaccessor>().HttpContext.User);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env,IServiceProvider ServiceProvider,ILoggerFactory loggerFactory)
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
context.Database.EnsureCreated();
}
app.UseMiddleware<RequestResponseLoggingMiddleware>();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/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.UseStaticfiles();
app.UseRouting();
app.UseAuthorization();
app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
});
loggerFactory.AddFile("Logs/ts-{Date}.txt");
Extensions.CreateRoles(ServiceProvider).Wait();
}
没有错误返回200