Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Web.Config Authentication Mode

Say I have the following web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authentication mode="Windows"></authentication>
    </system.web>
</configuration>

Using ASP.NET C#, how can I detect the Mode value of the Authentication tag?

like image 983
GateKiller Avatar asked Sep 18 '08 11:09

GateKiller


2 Answers

The mode property from the authenticationsection: AuthenticationSection.Mode Property (System.Web.Configuration). And you can even modify it.

// Get the current Mode property.
AuthenticationMode currentMode = 
    authenticationSection.Mode;

// Set the Mode property to Windows.
authenticationSection.Mode = 
    AuthenticationMode.Windows;

This article describes how to get a reference to the AuthenticationSection.

like image 170
Paul van Brenk Avatar answered Sep 18 '22 18:09

Paul van Brenk


Import the System.Web.Configuration namespace and do something like:

var configuration = WebConfigurationManager.OpenWebConfiguration("/");
var authenticationSection = (AuthenticationSection)configuration.GetSection("system.web/authentication");
if (authenticationSection.Mode == AuthenticationMode.Forms)
{
  //do something
}
like image 21
bkaid Avatar answered Sep 20 '22 18:09

bkaid