我在使用membership.createuser方法时遇到问题。我的代码如下,我得到一个null异常作为运行时。非常感谢任何帮助。
Dim username As String = userNameTxt.Text
Dim password As String = passwordTxt.Text
Dim email As String = emailTxt.Text
Dim status As New MembershipCreateStatus
Dim blank As String = ""
Dim provider As MembershipProvider
Dim providerUserKey As New System.Object
Dim user As MembershipUser
user = provider.CreateUser(username, password, email, blank, blank, True, providerUserKey, status)
答案 0 :(得分:2)
您需要具体实现MembershipProvider抽象类 您可以创建自己的或使用现有的。您还需要在web.config中设置它:
<connectionStrings>
<add name="MySqlConnection" connectionString="Data Source=MySqlServer;Initial Catalog=aspnetdb;Integrated Security=SSPI;" />
</connectionStrings>
<system.web>
...
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MySqlConnection"
applicationName="MyApplication"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
http://msdn.microsoft.com/en-us/library/ff648345.aspx
然后你可以使用Membership.CreateUser,不需要创建实例,它是静态的 它还有一个在web.config中设置的默认成员资格提供程序的属性:Membership.Provider
答案 1 :(得分:0)
Dim provider As MembershipProvider
然后
provider.CreateUser(..
提供程序为null,因为您尚未实际创建新实例
答案 2 :(得分:0)
使用Membership类上的共享方法。您必须配置要在web.config文件中使用的成员资格提供程序。
然后就是这样:
Membership.CreateUser(username, password, email, blank, blank, True, providerUserKey, status)
有关如何配置会员提供商的详细信息,请参阅msdn Memberhip doc