Membership user in ASP.NET MVC3
I have been working on ASP.Net MVC3. I created view and controller. Also, I have a model to create account.
Controller:
[HttpPost]
public A开发者_如何学编程ctionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
----> if (model.UserName == "Guven" && model.Password == "12345")
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "aaaaaaaaaaaaaaaaaa.");
}
}
return View(model);
}
I want to make from the database to control that the line marked on the above code.My question is:How can I do that controller?
If you're using MembershipProvider
it has the ValidateUser
Method.
you'll need to change your marked line to:
if (Membership.ValidateUser(model.UserName, model.Password))
If your not using MembershipProvider
yet, you'll might want to implement it.
There are two primary reasons for creating a custom membership provider.
You need to store membership information in a data source that is not supported by the membership providers included with the .NET Framework, such as a FoxPro database, an Oracle database, or other data sources.
You need to manage membership information using a database schema that is different from the database schema used by the providers that ship with the .NET Framework. A common example of this would be membership data that already exists in a SQL Server database for a company or Web site.
Have a look at: Sample Membership Provider Implementation
精彩评论