title: Dynamic MVC [authorization] for multiple domains
body: <p>I am currently developing an MVC intranet web app.  The same web app will be deployed across multiple domains.  I am using windows authorization and authorizing against groups in app's local domain. I am decorating my controller actions with the [authorize] attribute to protect certain actions.</p>
  
  <pre><code>    [Authorize(Roles = @"Domain1\AppUsers")]
      public ActionResult Index()
      {
          return View();
      }
  </code></pre>
  
  <p>Because this app will soon be deployed to Domain2, this means I will have to redecorate all of my authorized controller actions.  I would rather not have to deploy different code to each domain. Is there a way to make my authorization attribute "domain aware?"</p>
  
  <p>One thought I had considered was setting the domain name in the web.config </p>
  
  <pre><code>&lt;appSettings&gt;
  &lt;add key="AppDomainSecurityContext" value="Domain1"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>And then recalling it into the controller and storing it as a string</p>
  
  <p><code>string AppDomainSecurityContext = System.Web.Configuration.WebConfigurationManager.AppSettings["AppDomainSecurityContext"].ToString();</code></p>
  
  <p>But then how do I get that variable into the authorize attribute...</p>
  
  <p><code>[Authorize(Roles = "" + AppDomainSecurityContext + "\AppUsers")]</code></p>
  
  <p>Doesn't work.  Is there a better way?  Suggestions? </p>