成功登录后,asp.net core 2.2重定向到登录 [英] asp.net core 2.2 redirects to login after successful sign in
问题描述
- 我将我的Visual Studio 2017更新到了最新的15.9.5.
我用个人用户帐户创建了一个现成的asp.net core 2.2 web mvc项目.我设置了数据库(从程序包管理器控制台中更新数据库),并在IIS Express中运行了该站点.至此一切都很好.注册了用户并可以登录.
I have created an out the box asp.net core 2.2 web mvc project with individual user accounts. I set the db up (update-database from package manager console) and ran the site in IIS Express. All good to this point. Registered a user and could sign in.
将应用程序部署到IIS-在默认站点下作为应用程序运行,并且在成功登录后卡住了重定向回登录页面的情况. (所有部署正确-应用=无托管代码)
Deployed the app to IIS - running as an application under the default site and its stuck redirecting back to the login page after successfully signing in. (All deployed correctly - app = no managed code)
因此,我将项目提交到一个存储桶中,并请一个朋友在他们的计算机上尝试.有了IIS Express和数据库,我已经把它卡住了-成功登录后重定向回登录.
So I commit the project to a bit bucket repo and ask a friend to try this on their machine. With IIS Express and the database I have given him it's stuck - redirecting back to login after successful sign.
没有自定义代码-所有脚手架代码.
No custom code - all scaffolded code.
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?}");
});
}
}
}
推荐答案
我遇到了同样的问题,我在Mac上执行了以下操作,问题已解决.
I had the same issue, I run following on my mac and issue resolved.
sudo dotnet dev-certs https --trust;
这篇关于成功登录后,asp.net core 2.2重定向到登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!