SqlMembershipProvider With Aspnet_regsql.exe And Web.Config Configurations

436 views Asked by At

I use System.Web.Security.SqlMembershipProvider and Aspnet_regsql.exe. I installed the tables from Aspnet_regsql.exe into database with name UserAuthentication but when I run this code nothing goes to Aspnet_regsql.exe tables in database UserAuthentication. Where is the mistake here what else am I misssing ?

[HttpPost]
        public ActionResult Submit(User user)
        {
            SqlMembershipProvider provider = new SqlMembershipProvider();
            MembershipCreateStatus status = MembershipCreateStatus.Success;


            provider.CreateUser(user.Username, user.Password, string.Empty, string.Empty, string.Empty, true, null, out status);

            return RedirectToAction("Index", "Login");
        }

ConnectionString:

<add name="MySqlConnection" connectionString="Data
    Source=DOTNET-DEV9;Initial Catalog=UserAuthentication;Integrated
    Security=SSPI;" />

SqlProvider:

<authentication mode="Forms">
      <forms loginUrl="Login/Index" 
        name=".ASPXFORMSAUTH" />
    </authentication>
    <authorization>
      <!--<deny users="?" />-->
    </authorization>
    <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>
1

There are 1 answers

2
Roman Pushkin On BEST ANSWER

Try this:

    MembershipUser membershipUser = Membership.CreateUser(username, password, String.Empty);