如何注册在asp.net vnext认证类型名称 [英] How are Authentication type names registered in asp.net vnext
问题描述
所以,我更新了MongoDB的一个开源asp.net身份提供商,Asp.Net 3.0身份(又名vnext)工作。到目前为止,我已经能够注册提供商,创建用户,但使用时SignInManager如果一个正确的用户名,提供/通过我的错误
InvalidOperationException异常:下列身份验证类型不
受理:Microsoft.AspNet.Identity.Application
块引用>我的错误追踪到这里
<一href=\"https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHtt$p$psponse.cs\">https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHtt$p$psponse.cs但我似乎无法看到的SignInContext.Accepted名字是越来越添加到SignInContext。
我使用在VS14 CTP2中使用的所有vnext库的α-2版本
下面是我Startup.cs
公共无效配置(IBuilder应用程序)
{
尝试{
//有关如何配置应用程序的更多信息,请访问:http://go.microsoft.com/fwlink/?LinkID=398940
无功配置=新配置();
configuration.AddJsonFile(config.json);
configuration.AddEnvironmentVariables(); // app.UseLogRequests(试);
app.UseErrorPage(ErrorPageOptions.ShowAll);
app.UseServices(服务=&GT;
{ services.AddIdentity&LT;&MYUSER GT;()
.AddMongoDB&LT;&MYUSER GT;(configuration.Get(数据:MongoIdentity:ConnectionString的),configuration.Get(数据:MongoIdentity:数据库名))
.AddHttpSignIn&LT;&MYUSER GT;();
//添加MVC服务,以服务容器
services.AddMvc();
}); //静态文件添加到请求管道
app.UseStaticFiles(); app.UseMvc(路线=&GT;
{
routes.MapRoute(
名称:默认,
模板:{控制器} / {行动} / {?ID}
默认:新{控制器=家,行动=索引}); routes.MapRoute(
名称:API,
模板:API / {控制器} / {行动},
默认:新{行动=索引});
}); //基于Cookie的身份验证添加到请求管道
app.UseCookieAuthentication(新CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LOGINPATH =新PathString(/帐号/登录),
});
}
赶上(异常前)
{
Console.Write(ex.ToString());
扔;
}
}
解决方案原来我有设置MVC中的CookieAuthentication所以AuthenticationType未在MVC注册前,当它试图验证用户。由于MVC取决于验证我不得不撞它,MVC之前注册。
So I am updating an Open Source asp.net Identity provider for MongoDB to work with Asp.Net Identity 3.0 (aka vnext). So far I have been able to register the provider and create users but when using the SignInManager if a correct UserName/Pass is provided I get the error
InvalidOperationException: The following authentication types were not accepted: Microsoft.AspNet.Identity.Application
I have tracked down the error to here https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs
but I can't seem to see where the SignInContext.Accepted name is getting added to the SignInContext.
I am using the Alpha-2 versions of all of the vnext libraries that are being used in VS14 CTP2
Below is my 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; } }
解决方案Turns out I had setup MVC before the CookieAuthentication so the AuthenticationType was not registered in MVC when it tried to authenticate the user. As MVC depends upon the authentication I just had to bump it up and register it before MVC.
这篇关于如何注册在asp.net vnext认证类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!