SqlMembershipProvider与Aspnet_regsql.exe和Web.Config配置

时间:2013-12-10 09:06:10

标签: c# asp.net-mvc web-config sqlmembershipprovider

我使用System.Web.Security.SqlMembershipProviderAspnet_regsql.exe。我将Aspnet_regsql.exe中的表安装到名为UserAuthentication的数据库中,但是当我运行此代码时,没有任何内容转到数据库Aspnet_regsql.exe中的UserAuthentication表。这里的错误在哪里我还有什么错误?

[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 个答案:

答案 0 :(得分:1)

试试这个:

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