开发者

ASP.Net Using the Membership.CreateUser Method

I'm having issues using the membership.createuser method. My code is below, I get a null excepti开发者_如何学运维on as runtime. Any help is greatly appreciated.

    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)


you need concrete implementation of MembershipProvider abstract class you can either create your own or use existing one. You also need to set it in 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

then you can use Membership.CreateUser, no need to create instance, it's static it has also a property for default membership provider set in web.config: Membership.Provider


Use the shared methods on the Membership class. You will have to configure the membership provider to use in your web.config file.

Then it's simply:

Membership.CreateUser(username, password, email, blank, blank, True, providerUserKey, status)

For details on how to configure your membership provider, refer to msdn Memberhip doc


 Dim provider As MembershipProvider 

then

provider.CreateUser(..

provider is null as you haven't actually created a new instance

you should be using System.Web.Security.Membership.CreateUser

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜