Тип сущности ApplicationUser не является частью модели для текущего контекста. - PullRequest
0 голосов
/ 16 декабря 2018

Пожалуйста, скажите мне, где моя работа не так:

Я разработал и закодировал свой проект с самого начала без идентификации. Позднее, при создании программы, мне нужно было добавить идентификацию в мой проект.и я создал таблицы идентификаторов в базе данных программы.когда я загружаю http://localhost/account/login и я ввожу адрес электронной почты и пароль в окне входа в систему и нажимаю кнопку «ОК» ، я сталкиваюсь со следующей ошибкой. Также эта ошибка возникает, когда я хочу зарегистрировать пользователя. Screenshot of error Я также добавил следующее соединение к web.config:

<connectionStrings>
<add name="DefaultConnection" connectionString="metadata=res://*/Models.DomainModels.MachinaryModel.csdl|res://*/Models.DomainModels.MachinaryModel.ssdl|res://*/Models.DomainModels.MachinaryModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS2017;initial catalog=Machinary;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
<add name="MachinaryEntities" connectionString="metadata=res://*/Models.DomainModels.MachinaryModel.csdl|res://*/Models.DomainModels.MachinaryModel.ssdl|res://*/Models.DomainModels.MachinaryModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS2017;initial catalog=Machinary;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Accountcontroler / Login:

 Public Async Function Login(model As LoginViewModel, returnUrl As String) As Task(Of ActionResult)
        If Not ModelState.IsValid Then
            Return View(model)
        End If

        ' This doesn't count login failures towards account lockout
        ' To enable password failures to trigger account lockout, change to shouldLockout := True
        Dim result = Await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout:=False)
        Select Case result
            Case SignInStatus.Success
                Return RedirectToLocal(returnUrl)
            Case SignInStatus.LockedOut
                Return View("Lockout")
            Case SignInStatus.RequiresVerification
                Return RedirectToAction("SendCode", New With {
                    returnUrl,
                    model.RememberMe
                })
            Case Else
                ModelState.AddModelError("", "Invalid login attempt.")
                Return View(model)
        End Select
    End Function

IdentifyModels:

Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin

' You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
Public Class ApplicationUser
    Inherits IdentityUser
    Public Async Function GenerateUserIdentityAsync(manager As UserManager(Of ApplicationUser)) As Task(Of ClaimsIdentity)
        ' Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        Dim userIdentity = Await manager.CreateIdentityAsync(Me, DefaultAuthenticationTypes.ApplicationCookie)
        ' Add custom user claims here
        Return userIdentity
    End Function
End Class

Public Class ApplicationDbContext
    Inherits IdentityDbContext(Of ApplicationUser)
    Public Sub New()
        MyBase.New("DefaultConnection", throwIfV1Schema:=False)
    End Sub

    Public Shared Function Create() As ApplicationDbContext
        Return New ApplicationDbContext()
    End Function
End Class

startup.Auth.vb:

Partial Public Class Startup
    ' For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
    Public Sub ConfigureAuth(ByVal app As IAppBuilder)
        app.CreatePerOwinContext(AddressOf ApplicationDbContext.Create)
        app.CreatePerOwinContext(Of ApplicationUserManager)(AddressOf ApplicationUserManager.Create)
        app.CreatePerOwinContext(Of ApplicationSignInManager)(AddressOf ApplicationSignInManager.Create)
        ' Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(New CookieAuthenticationOptions With {
.AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
.LoginPath = New PathString("/Account/Login")
})


        ' Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie)

        ' Uncomment the following lines to enable logging in with third party login providers
        'app.UseMicrosoftAccountAuthentication(
        ' clientId: "",
        ' clientSecret: "");

        'app.UseTwitterAuthentication(
        ' consumerKey: "",
        ' consumerSecret: "");

        'app.UseFacebookAuthentication(
        ' appId: "",
        ' appSecret: "");

        'app.UseGoogleAuthentication();
    End Sub

End Class
...