lundi 8 juin 2015

Role Based Authorization in mvc

//when I am clicking on "GetRefferedData" it is asking me for login when I am inserting login credential it is not showing page details it is again asking for login page I think it is happening because in login action i use ADO.net and in Role Provider I am using entity framework but I dont know how to resolve this problem please help me.....
// this is my login Action code [HttpPost] public ActionResult Login(User user) { try { UserDetails _user = DataFacade.BusinessLayer.GetUserDetailsbyUserName(user.Username); if (_user.UserID > 0) { string salt = _user._passwordsalt; string hashedPassword = _user._password; string saltedPassword = user.Password + salt;

                    if (Crypto.VerifyHashedPassword(hashedPassword, saltedPassword))
                    {
                        TrackLoginUser(user.Username, "Web");
                        FormsAuthentication.SetAuthCookie(user.Username, false);
                        return RedirectToAction("Index", "Home");
                    }

                }
                return View();
            }
            catch(Exception ex)
            {
                _logHelper.Log(ex.ToString());
                return RedirectToAction("Login", "Account");
            }
        }

//My role provider class code 
 public override string[] GetRolesForUser(string username)
        {

            StgHappyMindsEntities db = new StgHappyMindsEntities();
            string s = db.users.Where(x => x.Username == username).FirstOrDefault().RoleName;
            string[] results = { s };
            return results;

        }

// this is my GetRefferedData action code
 [HttpGet]
       [Authorize(Roles = "Admin")]
        public ActionResult GetRefferedData()
        {
            List<GetRefferDetails> viewRefferDetails = new List<GetRefferDetails>();
            viewRefferDetails = DataFacade.BusinessLayer.GetReferredJobs();
            return View(viewRefferDetails);
        }

Aucun commentaire:

Enregistrer un commentaire