entity framework - ASP.NET MVC - user authorize in controller -
i have table in database names of users (with domains, example: domain1\user1). project has windows authentication. have 2 controllers - 1 logged in users , second specific user. table has 3 columns: (id, name, extra), "extra" fill user, admin (it has varchar: "admin").
want create such authorization, admin have access site second controller. how write it?
for suggestions appreciate.
in advance help. ;)
monic
====edit====
example: asp.net mvc 4 custom authorize attribute permission codes (without roles)
in 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 sth this, have no access site.
try this:
[authorizeuser(accesslevel = "admin")] public class securecontroller : controller { (...) }
hope help
update
public class authorizeuserattribute : authorizeattribute { public string accesslevel { get; set; } protected override bool authorizecore(httpcontextbase httpcontext) { if(httpcontext.user.identity.isauthenticated) { string privilegelevels = string.join("",getuserrights(httpcontext.user.identity.name.tostring()); if (privilegelevels.contains(this.accesslevel)) { return true; } else { return false; } } else return false; } } private string getuserrights(string username) { private report_dbent ren = new report_dbent(); return ren.users.where(u => u.username== username).select(u=>u.extra); }
Comments
Post a Comment