Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Can somebody give me some an example for using forms authentication in asp.net mvc4 with classical ado.net model??
Posted
Comments
usha C 14-Jul-14 3:00am    
[HttpPost]
[AllowAnonymous]
public ActionResult LoginUser(LoginModel logmodel, string returnUrl)
{
int i = 0;
bool isPersistent = false;

if (ModelState.IsValid)
{
if (Membership.ValidateUser(logmodel.username, logmodel.password))
{
string userData = "Application specific data for this user";

// FormsAuthentication.RedirectFromLoginPage(logmodel.username, logmodel.rememberme);

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,logmodel.username,
DateTime.Now,DateTime.Now.AddMinutes(30),isPersistent,userData,
FormsAuthentication.FormsCookiePath);

//Encrypt the ticket
string encTicket = FormsAuthentication.Encrypt(ticket);

//create the cookie
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

//Redirect back to original url
//return RedirectToAction(FormsAuthentication.GetRedirectUrl(logmodel.username,isPersistent));

i = 1;

}
else
{
ModelState.AddModelError("", "The username and password is incorrect");
}
}
if(i==1)

//return RedirectToAction("Index", "Home");
return RedirectToAction(FormsAuthentication.GetRedirectUrl(logmodel.username, isPersistent));

else
return View(logmodel);

}

This is my LoginController... when i try to run, im getting error like The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Login/Home/Index

Not sure what you mean by "classical ado.net model", but have a look here: Walkthrough: Using Forms Authentication in ASP.NET MVC[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900