如何将动态变量传递到ASP.NET MVC中的authorize属性类中?
例如,我有这段代码,如何将诸如userRoles变量之类的变量传递到Authorize属性类中?
private string userRoles; private string getuserRoles() { //Write your code to get userRoles userRoles = "admin"; return "admin"; } [Authorize(Roles = object.getuserRoles())] public ActionResult Admin() { ViewBag.Message = "Your contact page."; return View(); }
我的代码发出此错误
错误1属性参数必须是属性参数类型C:\ Users \ Nashat \ Downloads \ New文件夹(3)\ MvcPWy \ Controllers \ HomeController.cs的常数表达式,typeof表达式或数组创建表达式39 28 MvcPWy
因此,请任何人帮我解决此错误。