Проблемът е в внедряването на AccountController вместо default.
Добре. Ето го решението
Харесвам това Доставчици на членство и роли за PostgreSQLhttps://code.google.com/p/pgprovider / тъй като създава всички необходими таблици сам, когато стартира ))
Инсталирайте го:
Инсталационен пакет pgProvider
Добавяне към 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>
След това добавете и към Web.config:
<appSettings>
//---
<add key="enableSimpleMembership" value="false"/>
<add key="autoFormsAuthentication" value="false"/>
</appSettings>
След това изтрийте AccountController, създаден по подразбиране.
И най-накрая добавете 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);
}
}
Изходният код на доставчика е тук:https:/ /code.google.com/p/pgprovider/source/browse/trunk/pgProvider/pgMembershipProvider.cs
Това е всичко.
Работи с изгледи за влизане и регистрация, създадени по подразбиране.