When i create a custom AuthorizeAttribute to get my roles from a web.config file, users are authorized when the role does not exist.
I added a non-existing role like this:
[AuthorizeDynamic("ddd")]
How can i prevent users from being authorized when a role is not in the web.config file?
The AuthorizeAttribute
public class AuthorizeDynamicAttribute : AuthorizeAttribute
{
public AuthorizeDynamicAttribute(params string[] RoleKeys)
{
List<string> Roles = new List<string>(RoleKeys.Length);
var AllRoles = (NameValueCollection)ConfigurationManager.GetSection("Roles");
foreach (var Key in RoleKeys)
{
Roles.Add(AllRoles[Key]);
}
this.Roles = string.Join(",", Roles);
}
}
The web.config file
<Roles>
<add key="Administrator" value="Domain\Administrators" />
<add key="Employee" value="Domain\IIS_IUSRS" />
</Roles>