I'm using VB.NET MVC 5 with Identity 2.0.
我用VB。NET MVC 5和Identity 2.0。
I've been trying to configure my Startup.Auth to automatically use a single instance of ApplicationDbContext, CustomUserManager and CustomRoleManager per request as detailed in this tutorial.
我一直在尝试配置我的初创公司。Auth将自动地使用ApplicationDbContext、CustomUserManager和CustomRoleManager的单个实例,每个请求在本教程中详细介绍。
My code is as follows: (minus garbage)
我的代码如下:(减去垃圾)
Public Sub ConfigureAuth(app As IAppBuilder)
app.CreatePerOwinContext(ApplicationDbContext.Create)
' Error 135 Overload resolution failed because no accessible 'CreatePerOwinContext' can be called with these arguments:
' Extension method 'Public Function CreatePerOwinContext(Of T)(createCallback As System.Func(Of Microsoft.AspNet.Identity.Owin.IdentityFactoryOptions(Of T), Microsoft.Owin.IOwinContext, T)) As Owin.IAppBuilder' defined in 'Owin.AppBuilderExtensions': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
' Extension method 'Public Function CreatePerOwinContext(Of T)(createCallback As System.Func(Of T)) As Owin.IAppBuilder' defined in 'Owin.AppBuilderExtensions': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
app.CreatePerOwinContext(Of CustomUserManager)(CustomUserManager.Create)
' Error 136 Overload resolution failed because no accessible 'Create' accepts this number of arguments.
....
End Sub
But recieve these errors no matter what I do
但无论我做什么,都要接受这些错误
Overload resolution failed because no accessible 'Create' accepts this number of arguments.
重载解析失败,因为没有可访问的“Create”接受这个数目的参数。
I think it's to do with me writing in VB and the example being in C#, though it infuriates me that this is a problem. My CustomUserManager is a Public Class, and the Create method is Public Shared.
我认为这与我用VB写和用c#做例子有关,尽管这是一个问题让我很生气。我的CustomUserManager是一个公共类,创建方法是公共共享的。
Public Shared Function Create(options As IdentityFactoryOptions(Of CustomUserManager), context As IOwinContext) As CustomUserManager
Dim manager As CustomUserManager
manager = New CustomUserManager(New CustomUserStore(context.Get(Of ApplicationDbContext)()))
manager.UserValidator = New UserValidator(Of ApplicationUser, Integer)(manager)
manager.PasswordValidator = New PasswordValidator() With {
.RequiredLength = 6
}
manager.RegisterTwoFactorProvider("EmailCode",
New EmailTokenProvider(Of ApplicationUser, Integer)() With {
.Subject = "Security Code",
.BodyFormat = "Your security code is: {0}"
}
)
manager.EmailService = New EmailService()
manager.SmsService = New SmsService()
If Not options.DataProtectionProvider Is Nothing Then
manager.UserTokenProvider = New DataProtectorTokenProvider(Of ApplicationUser, Integer)(options.DataProtectionProvider.Create("ASP.NET Identity"))
End If
Return manager
End Function
Any ideas anyone? Any help is much appreciated, Cheers.
有什么想法吗?非常感谢您的帮助,干杯。
2 个解决方案
#1
#2
0
If you have already updated your visual studio 2013 with Update 3. This comes with all the identity stuff and custom user manager, role manager and many more.
如果你已经用更新3更新了你的visual studio 2013。这包括了所有的身份信息、自定义用户管理器、角色管理器等等。
Create new project using MVC template and Authentication selected as Individual User Accounts using Visual Studio 2013. Then you will get created all the code same as you have already implemented using the example. You can use that classes and implementation in order to fix your issues with your custom user manager.
使用MVC模板创建新项目,并使用Visual Studio 2013作为个人用户帐户进行身份验证。然后,您将创建与使用示例实现的所有代码相同的代码。您可以使用该类和实现来修复与自定义用户管理器的问题。
Check the floder App_Start >> IdentityConfig.vb
检查floder App_Start >> IdentityConfig.vb
Only thing I can see in your code, you have used integer as Id rather than string. That won't be a problem if you have correctly bind EF model biding stuff.
在您的代码中,我只能看到,您使用整数作为Id而不是字符串。如果您正确地绑定了EF模型,那么这就不是问题了。
#1
2
Try this
试试这个
Public Sub ConfigureAuth(app As IAppBuilder)
app.CreatePerOwinContext(AddressOf ApplicationDbContext.Create)
End Sub
The AddressOf operator creates a function delegate that points to the function specified by procedurename
AddressOf运算符创建一个函数委托,该委托指向程名指定的函数
link1
link2
#2
0
If you have already updated your visual studio 2013 with Update 3. This comes with all the identity stuff and custom user manager, role manager and many more.
如果你已经用更新3更新了你的visual studio 2013。这包括了所有的身份信息、自定义用户管理器、角色管理器等等。
Create new project using MVC template and Authentication selected as Individual User Accounts using Visual Studio 2013. Then you will get created all the code same as you have already implemented using the example. You can use that classes and implementation in order to fix your issues with your custom user manager.
使用MVC模板创建新项目,并使用Visual Studio 2013作为个人用户帐户进行身份验证。然后,您将创建与使用示例实现的所有代码相同的代码。您可以使用该类和实现来修复与自定义用户管理器的问题。
Check the floder App_Start >> IdentityConfig.vb
检查floder App_Start >> IdentityConfig.vb
Only thing I can see in your code, you have used integer as Id rather than string. That won't be a problem if you have correctly bind EF model biding stuff.
在您的代码中,我只能看到,您使用整数作为Id而不是字符串。如果您正确地绑定了EF模型,那么这就不是问题了。