所以我正在更新MongoDB的开源asp.net身份提供程序。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。可接受的名称正在被添加到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;
}
}
原来我在CookieAuthentication之前设置了MVC,所以当AuthenticationType试图对用户进行身份验证时,它没有在MVC中注册。由于MVC依赖于身份验证,我只需要在MVC之前将其注册。