我已经广泛研究了Google和此站点,并且找不到答案。我正在尝试将ASP.NET标识添加到Visual Studio,并且我一直在使用this page。在VB中使用ASP.NET标识
问题是,该文章中的所有内容都在C#中,而我的项目特别在Visual Basic中(ASP.NET Framework 4.5.1,而不是 MVC)。另外,我对Web开发人员太陌生,无法确切知道要改变什么。我发现了一个C#到VB转换器,它的大部分工作,但我仍然失去了一些东西,因为我得到了VS内的错误。即使我不明白为什么,我甚至不能100%确定我能够使用VB代替C#工作。
我想尽可能保持简洁,所以我将在中加上大写字母。
这是register.aspx页:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Register.aspx.vb" Inherits="WebFormsIdentity.Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; font-size: small">
<form id="form1" runat="server">
<div>
<h4 style="font-size: medium">Register a new user</h4>
<hr />
<p>
<asp:Literal runat="server" ID="StatusMessage" />
</p>
<div style="margin-bottom:10px">
<asp:Label runat="server" AssociatedControlID="UserName">User name</asp:Label>
<div>
<asp:TextBox runat="server" ID="UserName" />
</div>
</div>
<div style="margin-bottom:10px">
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<div>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
</div>
</div>
<div style="margin-bottom:10px">
<asp:Label runat="server" AssociatedControlID="ConfirmPassword">Confirm password</asp:Label>
<div>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
</div>
</div>
<div>
<div>
<asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" />
</div>
</div>
</div>
</form>
</body>
</html>
在VB中没有错误,但在运行页面后,我得到在浏览器中的“分析器错误”:“分析器错误信息:未能加载键入'WebFormsIdentity.Register'。“
这是背后的代码;大部分的问题都与此页:
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports System.Linq
Namespace WebFormsIdentity
Partial Public Class Register
Inherits System.Web.UI.Page
Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
' Default UserStore constructor uses the default connection string named: DefaultConnection
Dim userStore = New UserStore(Of IdentityUser)()
Dim manager = New UserManager(Of IdentityUser)(userStore)
Dim user = New IdentityUser() With { _
Key .UserName = UserName.Text _
}
Dim result As IdentityResult = manager.Create(user, Password.Text)
If result.Succeeded Then
StatusMessage.Text = String.Format("User {0} was created successfully!", user.UserName)
Else
StatusMessage.Text = result.Errors.FirstOrDefault()
End If
End Sub
End Class
End Namespace
在根据“暗淡用户”行,字键“”有此错误:
Name of field or property being initialized in an object initializer must start with '.'.
在与'行昏暗的结果 '字 '密码' 有这样:
'Password' is not declared. It may be inaccessible due to its protection level
上线下' result.S ucceeded”,字 'StatusMessage' 有这样:
'StatusMessage' is not declared. It may be inaccessible due to its protection level.
最后,同一行, 'user.UserName' 有这样:
'UserName' is not a member of 'System.Security.Principal.IPrincipal'.
我只是一直在使用VB进行大约六个星期,所以我是一个婴儿开发。我知道如何声明,但我不明白为什么上面的链接作者不需要在代码中做任何额外的事情,除了它是C#。
无论如何,感谢您阅读和提前协助。
谢谢!我会给它一个镜头,让你知道。 – Wullaj
如果我能'upvote'你的答案,我会的。 “关键”参考绝对是一个问题。感谢您的帮助! – Wullaj