Asp.net mvc 4 公共重写字符串[]GetRolesForUser(字符串用户名)

Asp.net mvc 4 公共重写字符串[]GetRolesForUser(字符串用户名),asp.net-mvc-4,authentication,authorization,Asp.net Mvc 4,Authentication,Authorization,大家好,这是我的问题,我在我的数据库上的角色下创建了身份验证,所以当我放置[Authorize(Roles=“admin”)]时,它将由我的程序读取,我已经在我的web.config和create类中设置了它,但当未授权时,它仍会在我的登录页面中作为默认值引导我,请帮助 这是我的密码 MyRoleProvider.cs public override string[] GetRolesForUser(string username) { UserDbEntitie

大家好,这是我的问题,我在我的数据库上的角色下创建了身份验证,所以当我放置[Authorize(Roles=“admin”)]时,它将由我的程序读取,我已经在我的web.config和create类中设置了它,但当未授权时,它仍会在我的登录页面中作为默认值引导我,请帮助

这是我的密码

MyRoleProvider.cs

public override string[] GetRolesForUser(string username)
        {
        UserDbEntities OE = new UserDbEntities();
        string s = OE.UserAccounts.Where(x => x.Username == username).FirstOrDefault().Role;
        string[] resultS = {s};
        return resultS; 
    }
控制器

 public class CustomerController : Controller
    {
    private UserDbEntities db = new UserDbEntities();

    // GET: Customer
    [Authorize(Roles="admin")]
    public ActionResult Index()
    {
        return View(db.Customers.ToList());
    }
Web.config

 <authentication mode="Forms">
          <forms loginUrl="Account/Login"></forms>
        </authentication>
        <roleManager enabled="true" defaultProvider="MyProvider">
          <providers>
          <clear/>
        <add name ="MyProvider" type="Sample.MyRoleProvider"/>
      </providers>   
    </roleManager>

您找到解决此问题的方法了吗?