sql >> Database teknologi >  >> RDS >> PostgreSQL

Asp.net MVC4, PostgreSQL og SimpleMembership

Problemet er i implementeringen af ​​en AccountController i stedet for standard.

Okay. Her er løsningen

Jeg kan godt lide dette medlemskab og rolleudbydere for PostgreSQLhttps://code.google.com/p/pgprovider / fordi den opretter alle nødvendige tabeller af sig selv, når den starter ))

Installer det:

Installer-pakke pgProvider

Tilføj til 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>

Tilføj derefter til Web.config også:

  <appSettings>
    //---
    <add key="enableSimpleMembership" value="false"/>
    <add key="autoFormsAuthentication" value="false"/>    
  </appSettings>

Slet derefter AccountController oprettet som standard.

Og tilføj endelig 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);
}

}

Udbyderens kildekode er her:https:/ /code.google.com/p/pgprovider/source/browse/trunk/pgProvider/pgMembershipProvider.cs

Det er alt.

Det fungerer med login- og registervisninger, som er oprettet som standard.




  1. RDBMS vs NoSQL

  2. PHP eval() kode i mellem <?php ?> fra databasen

  3. Hvordan løses UPDATE-kommandoen nægtet bruger i mysql?

  4. Kortslutter MySQL IF()-funktionen?