I have table in my database with names of users (with domains, for example: Domain1\user1). My project has Windows Authentication. I have two controllers - one for all logged in users and second for specific user. My table has 3 columns: (Id, Name, Extra), where "Extra" is only fill for user, who is admin (it has varchar: "admin").
I want to create such authorization, where only admin will have access to site with second controller. How to write it?
For any suggestions I will be very appreciate.
Thanks in advance for help. ;)
Monic
====Edit====
from example: ASP.NET MVC 4 Custom Authorize Attribute with Permission Codes (without roles)
In my main controller:
[AuthorizeUser(AccessLevel = "Extra")]
public class SecureController : Controller
{
(...)
}
public class AuthorizeUserAttribute : AuthorizeAttribute
{
public string AccessLevel { get; set; }
private Report_DBEnt REn = new Report_DBEnt();
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var isAuthorized = base.AuthorizeCore(httpContext);
if (!isAuthorized)
{
return false;
}
string privilegeLevels = string.Join("", REn.Users.Where(u => u.Extra.Equals("admin")).FirstOrDefault());
if (privilegeLevels.Contains(this.AccessLevel))
{
return true;
}
else
{
return false;
}
}
}
I've tried use it sth like this, but I have no access to my site.