ASP.NET MVC 需要绕过 "HTTPS required" 消息

ASP.NET MVC Need to bypass "HTTPS required" message

我按照 link 共享上的教程安装了 Identity Manager (https://www.scottbrady91.com/ASPNET-Identity/Identity-Manager-using-ASPNET-Identity)。我的本地主机项目还没有 SSL,需要一种方法来绕过当我转到 运行 项目时弹出的 "HTTPS required" 消息。我认为下面的 Startup class 可能是我需要做某事的地方,但不确定。我还尝试在 Visual Studios 中查找设置,并在 IIS 中四处寻找解决此问题的方法,但没有成功。

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var factory = new IdentityManagerServiceFactory();
        factory.IdentityManagerService =
          new Registration<IIdentityManagerService>(Create());

        app.UseIdentityManager(new IdentityManagerOptions { Factory = factory });
    }

    private IIdentityManagerService Create()
    {
        var context =
          new IdentityDbContext(
            @"Data Source=.\SQLEXPRESS;Initial Catalog=AspIdentity;Integrated Security=false");

        var userStore = new UserStore<IdentityUser>(context);
        var userManager = new UserManager<IdentityUser>(userStore);

        var roleStore = new RoleStore<IdentityRole>(context);
        var roleManager = new RoleManager<IdentityRole>(roleStore);

        var managerService =
          new AspNetIdentityManagerService<IdentityUser, string, IdentityRole, string>
            (userManager, roleManager);

        return managerService;
    }

}

好吧,花了一天时间四处看看,但在我发布这个问题后就找到了答案。我在 applicationhost.config 文件中发现了一个更改的文件,其中添加了以下行:

<binding protocol="https" bindingInformation="*:44380:localhost" />

通过将 URL 中的端口更改为那个,我能够解决这个问题。

IdentityManagerOptions 包含一个 SecurityConfiguration property, which itself contains a RequireSsl 属性,您可以将其设置为 false

var factory = new IdentityManagerServiceFactory();
factory.IdentityManagerService = new Registration<IIdentityManagerService>(Create());

var identityManagerOptions = new IdentityManagerOptions { Factory = factory };
identityManagerOptions.SecurityConfiguration.RequireSsl = false;

app.UseIdentityManager(identityManagerOptions);