public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                
                
                if (Membership.ValidateUser(model.UserName, model.Password))
                {

                    var user = Membership.GetUser(model.UserName);

                    //Find user if the user is allready registered
                    var identity = _userManager.GetUser(user.ProviderUserKey.ToString());
                        //UsersStorage.UserIdentities.Find(u => u.Id == user.ProviderUserKey.ToString());


                    if (identity != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                        _userManager.SetCurrentUser(identity);

                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "User is not allowed to login.");
                    }
                    
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            //get Providers
            var hrdClient = new HrdClient();
            var fam = FederatedAuthentication.WSFederationAuthenticationModule;
            var request = new HrdRequest(fam.Issuer, fam.Realm, context: Request.QueryString["ReturnUrl"]);
            var hrdIdentityProviders = hrdClient.GetHrdResponse(request);
            model.Providers = hrdIdentityProviders
                                    .Select(hrd => new IdentityProviderModel()
                                                       {
                                                           Name = hrd.Name,
                                                           LoginUrl = hrd.LoginUrl,
                                                           LogoutUrl = hrd.LogoutUrl
                                                       });

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        //
        // GET: /Account/LogOn

        public ActionResult LogOn()
        {
            var hrdClient = new HrdClient();


            //get Providers
            var fam = FederatedAuthentication.WSFederationAuthenticationModule;
            var request = new HrdRequest(fam.Issuer, fam.Realm, context: Request.QueryString["ReturnUrl"]);
            var hrdIdentityProviders = hrdClient.GetHrdResponse(request);

            var logon = new LogOnModel()
                            {
                                Providers = hrdIdentityProviders
                                    .Select(hrd => new IdentityProviderModel()
                                                       {
                                                           Name = hrd.Name,
                                                           LoginUrl = hrd.LoginUrl,
                                                           LogoutUrl = hrd.LogoutUrl
                                                       })
                            };

            return View(logon);
        }