Masalahnya adalah dalam implementasi AccountController, bukan default.
Oke. Ini solusinya
Saya menyukai Penyedia Keanggotaan dan Peran untuk PostgreSQLhttps://code.google.com/p/pgprovider / karena itu membuat semua tabel yang diperlukan dengan sendirinya saat dimulai ))
Instal:
Instal-Paket pgProvider
Tambahkan ke Web.config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<connectionStrings>
<add name="MovieDBContext" connectionString="Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=000;" providerName="Npgsql" />
<add name="pgProvider" connectionString="Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=000;" providerName="Npgsql" />
</connectionStrings>
<membership defaultProvider="pgMembershipProvider">
<providers>
<clear />
<add name="pgMembershipProvider" type="pgProvider.pgMembershipProvider, pgProvider" applicationName="MvcMovie"/>
</providers>
</membership>
<roleManager defaultProvider="pgRoleProvider">
<providers>
<clear />
<add name="pgRoleProvider" type="pgProvider.pgRoleProvider, pgProvider" applicationName="MvcMovie"/>
</providers>
</roleManager>
Kemudian tambahkan juga ke Web.config:
<appSettings>
//---
<add key="enableSimpleMembership" value="false"/>
<add key="autoFormsAuthentication" value="false"/>
</appSettings>
Kemudian hapus AccountController yang dibuat secara default.
Dan terakhir tambahkan AccountController:
public class AccountController : Controller
{
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
return View(model);
}
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return RedirectToAction("Login", "Account");
}
public ActionResult Register()
{
return View();
}
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
MembershipCreateStatus status;
MembershipUser membershipUser = (Membership.Provider).CreateUser(
model.UserName, model.Password, null,null,null, true, null, out status);
if (membershipUser != null)
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Registration error");
}
}
return View(model);
}
}
Kode sumber penyedia ada di sini:https:/ /code.google.com/p/pgprovider/source/browse/trunk/pgProvider/pgMembershipProvider.cs
Itu saja.
Ini bekerja dengan tampilan Login dan Daftar, yang dibuat secara default.