title: How to pass a dynamic variable into the authorize attribute class in asp.net mvc?
body: <p>How to pass a dynamic variable into the authorize attribute class in asp.net mvc?</p>
  
  <p>For Example I have this piece of code, how can I pass a variable like userRoles variable into the Authorize attribute class?</p>
  
  <pre><code>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();
  
  }
  </code></pre>
  
  <p>My code issues this error</p>
  
  <blockquote>
    <p>Error 1   An attribute argument must be a constant expression, typeof
    expression or array creation expression of an attribute parameter
    type  C:\Users\Nashat\Downloads\New folder
    (3)\MvcPWy\Controllers\HomeController.cs  39  28  MvcPWy</p>
  </blockquote>
  
  <p>So please could anyone help me to resolve this error. </p>