Il problema è nell'implementazione di un AccountController invece di default.
Ok. Ecco la soluzione
Mi piace questo abbonamento e provider di ruoli per PostgreSQLhttps://code.google.com/p/pgprovider / perché crea tutte le tabelle necessarie da solo all'avvio ))
Installalo:
Pacchetto di installazione pgProvider
Aggiungi a 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>
Quindi aggiungi anche a Web.config:
<appSettings>
//---
<add key="enableSimpleMembership" value="false"/>
<add key="autoFormsAuthentication" value="false"/>
</appSettings>
Quindi elimina AccountController creato per impostazione predefinita.
E infine aggiungi 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);
}
}
Il codice sorgente del provider è qui:https:/ /code.google.com/p/pgprovider/source/browse/trunk/pgProvider/pgMembershipProvider.cs
Questo è tutto.
Funziona con le viste Login e Register, quella creata per impostazione predefinita.