![](/img/trans.png)
[英]ASP.NET Core 3.1.1 Jwt redirects instead of returning http status 401 after migration from ASP.NET Core 2.2
[英]asp.net core 2.2 redirects to login after successful sign in
我已經使用個人用戶帳戶創建了一個現成的asp.net core 2.2 web mvc項目。 我設置了數據庫(從程序包管理器控制台更新數據庫),並在IIS Express中運行了該站點。 至此一切都很好。 已注冊用戶並可以登錄。
將應用程序部署到IIS-在默認站點下作為應用程序運行,並且在成功登錄后卡住了重定向回到登錄頁面的情況。(所有部署正確-app =無托管代碼)
因此,我將該項目提交給了一些存儲區回購,並請朋友在他們的計算機上進行嘗試。 有了IIS Express和數據庫,我已經把它卡住了-成功登錄后重定向回登錄。
沒有自定義代碼-所有腳手架代碼。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
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.UseCookiePolicy();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
我認為EF無法訪問您的數據庫。 通過使用DefaultConnection中的連接設置,確保數據庫可訪問。 將調試器設置為登錄方法,並檢查UserManager方法返回的內容。
我遇到了同樣的問題,我在Mac上執行了以下操作,問題已解決。
sudo dotnet dev-certs https --trust;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.