成功登录后,asp.net core 2.2重定向到登录

时间:2019-01-24 19:45:04

标签: c# asp.net asp.net-core asp.net-identity

  • 我将Visual Studio 2017更新到了最新的15.9.5。

我已经使用个人用户帐户创建了一个现成的asp.net core 2.2 web mvc项目。我设置了数据库(从程序包管理器控制台更新数据库),并在IIS Express中运行了该站点。至此一切都很好。注册用户并可以登录。

将应用程序部署到IIS-在默认站点下作为应用程序运行,并且在成功登录后卡住了重定向回登录页面的情况。 (所有部署正确-应用=没有托管代码)

因此,我将项目提交到一个存储桶中,并请一个朋友在他们的计算机上尝试。有了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?}");
        });
    }
}

}

2 个答案:

答案 0 :(得分:0)

我认为EF无法访问您的数据库。通过使用DefaultConnection中的连接设置,确保数据库可访问。将调试器设置为登录方法,并检查UserManager方法返回的内容。

答案 1 :(得分:0)

我遇到了同样的问题,我在Mac上执行了以下操作,问题已解决。

sudo dotnet dev-certs https --trust;