RepeatHost Business Hosting

Get Authentication Mode from Web.Config file

If you want to find out programmatically what authentication mode the current ASP.NET website is running under you can actually read it from the web.config file using the code below.

System.Web.Configuration.AuthenticationSection section = 
    (System.Web.Configuration.AuthenticationSection)System.Web.Configuration.WebConfigurationManager.GetSection("system.web/authentication");
if (section.Mode == System.Web.Configuration.AuthenticationMode.Windows)
{
    // Do something because it is running under Windows mode
}
else if (section.Mode == System.Web.Configuration.AuthenticationMode.None)
{
    // Do something because it is running under None mode
}
// etc.

If your web.config file's authentication section contained the following node:

<authentication mode="Forms">
</authentication>

Then the section.Mode would be:

section.Mode = System.Web.Configuration.AuthenticationMode.Forms