code_junkie

Detecting Web.Config Authentication Mode

Nov 10th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3. <system.web>
  4. <authentication mode="Windows"></authentication>
  5. </system.web>
  6. </configuration>
  7.  
  8. // Get the current Mode property.
  9. AuthenticationMode currentMode =
  10. authenticationSection.Mode;
  11.  
  12. // Set the Mode property to Windows.
  13. authenticationSection.Mode =
  14. AuthenticationMode.Windows;
  15.  
  16. var configuration = WebConfigurationManager.OpenWebConfiguration("/");
  17. var authenticationSection = (AuthenticationSection)configuration.GetSection("system.web/authentication");
  18. if (authenticationSection.Mode == AuthenticationMode.Forms)
  19. {
  20. //do something
  21. }
  22.  
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. XmlDocument config = new XmlDocument();
  26. config.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
  27. XmlNode node = config.SelectSingleNode("//configuration/system.web/authentication");
  28. this.Label1.Text = node.Attributes["mode"].Value;
  29. }
Add Comment
Please, Sign In to add comment