如何在asp.net vnext中注册身份验证类型名称

run*_*ier 11 c# asp.net asp.net-mvc asp.net-identity asp.net-core

因此,我正在更新MongoDB的开源asp.net身份提供程序,以便与Asp.Net Identity 3.0(又名vnext)一起使用.到目前为止,我已经能够注册提供程序并创建用户,但是当使用SignInManager时,如果提供了正确的UserName/Pass,我会收到错误

InvalidOperationException:未接受以下身份验证类型:Microsoft.AspNet.Identity.Application

我已经将错误跟踪到这里 https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs

但我似乎无法看到SignInContext.Accepted名称被添加到SignInContext的位置.

我正在使用VS14 CTP2中使用的所有vnext库的Alpha-2版本

下面是我的Startup.cs

public void Configure(IBuilder app)
    {
        try {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

         //   app.UseLogRequests("try");
            app.UseErrorPage(ErrorPageOptions.ShowAll);
            app.UseServices(services =>
            {

                services.AddIdentity<MyUser>()
                .AddMongoDB<MyUser>(configuration.Get("Data:MongoIdentity:ConnectionString"), configuration.Get("Data:MongoIdentity:DBName"))
                .AddHttpSignIn<MyUser>();


                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "api/{controller}/{action}",
                    defaults: new { action = "Index" });
            });

            // Add cookie-based authentication to the request pipeline
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
            });
        }
        catch (Exception ex)
        {
            Console.Write(ex.ToString());
            throw;
        }
    }
Run Code Online (Sandbox Code Playgroud)

run*_*ier 8

事实证明我在CookieAuthentication之前设置了MVC,因此在尝试验证用户时,AuthenticationType未在MVC中注册.由于MVC依赖于身份验证,我只需要将其提升并在MVC之前注册它.