title: Error message does not appear on failed login using asp.net mvc 4 with a custom role provider?
body: <p>I'm trying to implement a custom role provider and I found a tutorial and followed it. 
  Here is the link:  <a href="http://techbrij.com/custom-roleprovider-authorization-asp-net-mvc" rel="nofollow">http://techbrij.com/custom-roleprovider-authorization-asp-net-mvc</a></p>
  
  <p>When I try to login using a user account that does not exist, the error message does not appear. Here is my current code.</p>
  
  <p>Here is code for the login:</p>
  
  <pre><code>[HttpPost]
          [AllowAnonymous]
          [ValidateAntiForgeryToken]
          public ActionResult Login(LoginModel model, string returnUrl)
          {
              if (ModelState.IsValid)
              {
                  using (SampleDBEntities objContext = new SampleDBEntities())
                  {
                      var objUser = objContext.Users.FirstOrDefault(x =&gt; x.AppUserName == model.UserName &amp;&amp; x.Password == model.Password);
                      if (objUser == null)
                      {
                          ModelState.AddModelError("LogOnError", "The user name or password provided is incorrect.");
                      }
                      else
                      {
                          FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
  
                          if (Url.IsLocalUrl(returnUrl) &amp;&amp; returnUrl.Length &gt; 1 &amp;&amp; returnUrl.StartsWith("/")
                             &amp;&amp; !returnUrl.StartsWith("//") &amp;&amp; !returnUrl.StartsWith("/\\"))
                          {
                              ModelState.AddModelError("LogOnError", "The user name or password provided is incorrect.");
                              return Redirect(returnUrl);
                          }
                          else
                          {
                              //Redirect to default page
  
                              //return RedirectToAction("RedirectToDefault");
                              return RedirectToAction("Index", "Home");
                          }
                      }
                  }
              }
              // If we got this far, something failed, redisplay form
              return View(model);
          }
  </code></pre>
  
  <p>Here is the code for the implementation of the provider:</p>
  
  <pre><code>public class MyRoleProvider : RoleProvider
      {
          public override void AddUsersToRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override string ApplicationName
          {
              get
              {
                  throw new NotImplementedException();
              }
              set
              {
                  throw new NotImplementedException();
              }
          }
  
          public override void CreateRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
          {
              throw new NotImplementedException();
          }
  
          public override string[] FindUsersInRole(string roleName, string usernameToMatch)
          {
              throw new NotImplementedException();
          }
  
          public override string[] GetAllRoles()
          {
              throw new NotImplementedException();
          }
  
  
          public override string[] GetRolesForUser(string username)
          {
              using (SampleDBEntities objContext = new SampleDBEntities())
              {
                  var objUser = objContext.Users.FirstOrDefault(x =&gt; x.AppUserName == username);
                  if (objUser == null)
                  {
                      return null;
                  }
                  else
                  {
                      string[] ret = objUser.Roles.Select(x =&gt; x.RoleName).ToArray();
                      return ret;
                  }
              }
          }
  
          public override string[] GetUsersInRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool IsUserInRole(string username, string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override bool RoleExists(string roleName)
          {
              throw new NotImplementedException();
          }
      }
  }
  </code></pre>
  
  <p>Sir/Ma'am your answers would be of great help. Thank you++</p>