Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.Net MVC#[授权(角色)]_C#_Asp.net_Azure - Fatal编程技术网

Asp.Net MVC#[授权(角色)]

Asp.Net MVC#[授权(角色)],c#,asp.net,azure,C#,Asp.net,Azure,我正在尝试与我的定制经理进行基于角色的授权。我有用户表和角色表。模型看起来像这样 public class Account : EntityModel { public string Username { get; set; } public string PasswordHash { get; set; } public string Email { get; set; } public Account() : base("1", Suid

我正在尝试与我的定制经理进行基于角色的授权。我有用户表和角色表。模型看起来像这样

public class Account : EntityModel
{
    public string Username { get; set; }

    public string PasswordHash { get; set; }

    public string Email { get; set; }

    public Account()
        : base("1", Suid.NewSuid())
    {
        Roles = new List<String>();
    }

    public static IEnumerable<Account> GetAll()
    {
        return TableHelper.GetAll<Account>();
    }

    public List<String> Roles { get; set; }

    public Account Save()
    {
        TableHelper.Save<Account>(this);
        return this;
    }

}
public class Role : EntityModel
{
    public string Name { get; set; }
    public String Id
    {
        get
        {
            return this.RowKey;
        }
        set
        {
            this.RowKey = value;
        }
    }

    public Role()
        : base("1", Suid.NewSuid())
    {

    }

    public static IEnumerable<Role> GetAll()
    {
        return TableHelper.GetAll<Role>();
    }

    public static Role Get(string x)
    {
        return TableHelper.Get<Role>("1", x);
    }
}

但它不起作用。我遗漏了什么吗?

您是否添加了roleprovider以及它工作所需的其他功能


有一个类似的问题,它有一个很好的入门方法:

…为什么?ASP.NET Identity是否自带内置角色提供程序?什么时候脱光的?我想知道,因为只有在我最新的项目中,
Authorize(Roles=“role”)
才停止运行——在以前的所有项目中,它都能完美地运行,而无需创建或添加roleprovider。ASP.NET4.5.2,MVC5。它确实是现成的,但我想知道他的dbcontext设置是否正确。
[Authorize(Roles = "admin")]