I followed this tutorial to create a sample Login application using ASP.NET MVC
I have created the database and added it to the Server Explorer as mentioned in the tutorial. I also modified the AccountController.cs file and added the following code instead of the default Logon method.
public ActionResult Login(string username, string password, bool? rememberMe)
{
ViewData["Title"] = "Login";
if (Request.HttpMethod != "POST")
{
return View();
}
// Basic parameter validation
List<string> errors = new List<string>();
if (String.IsNullOrEmpty(username))
{
errors.Add("You must specify a username.");
}
if (errors.Count == 0)
{
LinkMVC.Models.LinkManagerDataContext lm = new LinkMVC.Models.LinkManagerDataContext();
Nullable<int> userid = null;
lm.fm_AuthenticateUser(username, password, ref userid);
if (userid > 0)
{
FormsAuth.SetAuthCookie(username, rememberMe ?? false);
return RedirectToAction("Index", "Home");
}
else
{
errors.Add("The username or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
ViewData["errors"] = errors;
ViewData["username"] = username;
return View();
}
I am not able to resolve two errors :
LinkMVC.Models.LinkManagerDataContext lm = new LinkMVC.Models.LinkManagerDataContext();
It says the type of namespace “Models” does not exist in namespace LinkMVC
FormsAuth.SetAuthCookie(username, rememberMe ?? false);
Here it says no extension method for setAuthCookie
Can someone tell me what I am missing over here?
Thanks
I think the class should be FormsAuthentication not FormsAuth.
The sample is from 2008 and is using ASP.NET MVC preview 4 so maybe the class name has changed.