我使用System.Web.Security.SqlMembershipProvider
和Aspnet_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>
答案 0 :(得分:1)
试试这个:
MembershipUser membershipUser = Membership.CreateUser(username, password, String.Empty);