我想尝试将角色作为参数发送,之后我想逐个匹配角色。
的ActionResult
[Yetki]
public ActionResult UserUpdate(int? id)
{
return View();
}
Yetki课程:
public class Yetki : AuthorizeAttribute
{
private readonly List<int> _allowedroles = new List<int>();
public Yetki()
{
List<int> roles = new List<int>(); //Role List
roles.Add(1); // Admin
roles.Add(2); // FirmaAdmin
roles.Add(3); // User
_allowedroles = roles;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool authorize = false;
if (HttpContext.Current.Session["Yetki"] != null)
{
int yetki = Convert.ToInt32(HttpContext.Current.Session["Yetki"]);
foreach (var rol in _allowedroles)
{
if (rol == yetki)
{
authorize = true;
}
}
}
return authorize;
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
我发布userUpdate后如何发送角色名称作为参数?之后我希望获得发布参数角色而不是按会话匹配?
感谢。