title: How to check Authentication Mode value in Web.Config without referencing System.Web
body: <p>I have a class that needs to check the Authentication Mode from a web.config.</p>
  
  <p>Ex:</p>
  
  <pre><code>&lt;authentication mode="Forms" /&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;authentication mode="Windows" /&gt;
  </code></pre>
  
  <p>Now, I know this can be done pretty easily with the following code:</p>
  
  <pre><code>AuthenticationSection sec = ConfigurationManager.GetSection("system.web/authentication");
  if (sec.Mode == "Windows")
  { ... }
  </code></pre>
  
  <p>My problem is, this class/project is being referenced in my Web project, as well as a WinForms project.  The WinForms project is requiring .NET 4.0 Client Profile Framework (we don't want to require the full .NET 4 Framework, if possible).  If I'm not mistaken, the Client Profile does not contain System.Web.dll.</p>
  
  <p>Is there a way that this value can be checked without referencing System.Web (and preferably without manually parsing the config file)?</p>
  
  <p>I've tried: </p>
  
  <pre><code>object authSection = ConfigurationManager.GetSection("system.web/authentication");
  if (authSection.ToString() == "Windows")
  { ... }
  </code></pre>
  
  <p>However the ToString() simply returns the string "System.Web.Configuration.AuthenticationSection".</p>
  
  <p>Thank you!</p>