我正在为mvc3应用程序实现用户权限管理。在自定义属性中查找mvc3操作方法参数
我已经定义与ControllerName,ActionName数据库我的操作方法和参数包括参数名称和参数类型等
我实现了从授权属性继承自定义属性。
我想要做的是找到在数据库中定义的内置操作之间执行的操作,并计算用户是否具有指定操作的权限。
代码是这样的;
[HttpPost]
[MyAuthorize]
public ActionResult Edit(VendorPageItem entity)
{
//...
}
public class MyAuthorize: System.Web.Mvc.AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
string controller = httpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
string action = httpContext.Request.RequestContext.RouteData.Values["action"].ToString();
int userId = SessionState.Current.LoginParameter.VendorUserID;
List<string> parameterTypes = new List<string>();
//TODO: Find out action method parameter types.
return IoCWorker.Resolve<IUserRightService>().HasUserRightToAction(userId, controller, action, parameterTypes);
}
}
我的问题是在我的自定义属性中找到方法参数类型。
谢谢。
编辑:忘记提及,这是后行动。 [HttpPost]加入。
我已经用'AuthorizeAttribute'这种方法玩过,但是发现只是在控制器方法中检查权限更简单。 –