I have added everything which i needed for this,But still its is not working (am first time with Identity)
Here is my code:
Controller
[Authorize(Roles = "Admin")]
public class AdminController : Controller
{
//Codes in the controller
}
MyRoleProvider
public override string[] GetRolesForUser(string username)
{
var result=adminService.LoginData();//which has Role,and other datas
string a=result.Where(x=>x.UserName==username).FirstOrDefault().Role;
string[] output={a};
return output;
}
Web.Config
<roleManager enabled="true" defaultProvider="MyProvider">
<providers>
<clear/>
<add name="MyProvider" type="bombays.MyRoleProvider"/>
</providers>
</roleManager>
Login like this
public ActionResult Login(Login log)
{
var p = adminService.adminLogin(log);
if (p.UserName == log.UserName && p.Password == log.Password)
{
Session["adminusername"] = p.UserName;
Session["adminname"]=p.name;
}
return View("AdminHome");
}
I have checked lot of example but nothing saves me. Now what is happening is ;Any user can view the page.Its not even calling GetRolesForUser function(tried with breakpoint)