mysql - Asp.net 表单 (VB.NET) 身份 + MySQL

标签 mysql asp.net vb.net forms identity

Asp.net 表单 (VB.NET) 身份 + MySQL

嗨,我正在尝试根据本教程编写代码。我想使用 MySql 和 Identity。 教程: https://learn.microsoft.com/en-us/aspnet/identity/overview/extensibility/implementing-a-custom-mysql-aspnet-identity-storage-provider

现在我的代码如下所示:

Imports AspNet.Identity.MySQL
Imports Microsoft.Owin.Security
Imports Microsoft.AspNet.Identity

Public Class ApplicationUser
    Inherits IdentityUser

End Class

Public Class ApplicationDbContext
    Inherits MySQLDatabase

    Public Sub New(ByVal connectionName As String)
        MyBase.New(connectionName)
    End Sub

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


#Region "Helpers"
Public Class UserManager
    Inherits UserManager(Of ApplicationUser)
    Public Sub New()
           MyBase.New(New UserStore(Of ApplicationUser)(New ApplicationDbContext()))
    End Sub
End Class
Public Class IdentityHelper

    Public Const XsrfKey As String = "xsrfKey"

    Public Shared Sub SignIn(manager As UserManager, user As ApplicationUser, isPersistent As Boolean)
        Dim authenticationManager As IAuthenticationManager = HttpContext.Current.GetOwinContext().Authentication
        authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie)
        Dim identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie)
        authenticationManager.SignIn(New AuthenticationProperties() With {.IsPersistent = isPersistent}, identity)
    End Sub

    Public Const ProviderNameKey As String = "providerName"
    Public Shared Function GetProviderNameFromRequest(request As HttpRequest) As String
        Return request(ProviderNameKey)
    End Function

    Private Shared Function IsLocalUrl(url As String) As Boolean
        Return Not String.IsNullOrEmpty(url) AndAlso ((url(0) = "/"c AndAlso (url.Length = 1 OrElse (url(1) <> "/"c AndAlso url(1) <> "\"c))) OrElse (url.Length > 1 AndAlso url(0) = "~"c AndAlso url(1) = "/"c))
    End Function

    Public Shared Sub RedirectToReturnUrl(returnUrl As String, response As HttpResponse)
        If Not [String].IsNullOrEmpty(returnUrl) AndAlso IsLocalUrl(returnUrl) Then
            response.Redirect(returnUrl)
        Else
            response.Redirect("~/")
        End If
    End Sub
End Class
#End Region

但是有一个错误(或多个错误)

MyBase.New(New UserStore(Of ApplicationUser)(New ApplicationDbContext())

我不懂 C#,很难继续学习本教程:

如何在 VB 中使用它?

非常感谢。

最佳答案

尝试将其更改为以下内容:

MyBase.New(New UserStore(Of ApplicationUser)(TryCast(context.[Get](Of ApplicationDbContext)(), MySQLDatabase)))

关于mysql - Asp.net 表单 (VB.NET) 身份 + MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50842957/

相关文章:

php mysql select 下拉选择和不同的查询

c# - 从枚举加载单选按钮列表时,如何在每个单选按钮旁边显示文本?

mysql - 与日期和时间作斗争

mysql - 使用 PHP 和 mysql 创建菜单层次结构 Bootstrap

MySQL select 检测组内互斥行冲突

mysql - 当我指定选择前 10 行时,有什么方法可以阻止 MySQL 读取整个表吗?

javascript - Microsoft OAuth 不返回刷新 token

c# - 防止 TFS 添加临时文件

vb.net - 在 VB.NET 中连接字符串的 & 与 plus

sql - 如何创建参数化 SQL 查询?我为什么要?