Vra

Sê Ek het die volgende Web.config:

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

Die gebruik van ASP.NET C #, hoe kan ek ontdek die modus waarde van die verifikasie tag?

Was dit nuttig?

Oplossing

Probeer Context.User.Identity.AuthenticationType

Gaan vir PB se antwoord mense

Ander wenke

Die modus eiendom van die authenticationsection: AuthenticationSection.Mode Eiendom (System.Web.Configuration) . En jy kan selfs verander dit.

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

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

In hierdie artikel word hoe om kry 'n verwysing na die AuthenticationSection .

Voer die System.Web.Configuration naamruimte en iets soos te doen:

var configuration = WebConfigurationManager.OpenWebConfiguration("/");
var authenticationSection = (AuthenticationSection)configuration.GetSection("system.web/authentication");
if (authenticationSection.Mode == AuthenticationMode.Forms)
{
  //do something
}

Jy kan ook die verifikasie af deur gebruik te maak van die statiese ConfigurationManager klas om die artikel en dan kry die enum AuthenticationMode.

AuthenticationMode authMode = ((AuthenticationSection) ConfigurationManager.GetSection("system.web/authentication")).Mode;

Die verskil tussen WebConfigurationManager en ConfigurationManager


As jy wil hê dat die naam van die konstante haal in die gespesifiseerde opsomming jy kan dit doen deur gebruik te maak van die Enum.GetName(Type, Object) metode

Enum.GetName(typeof(AuthenticationMode), authMode); // e.g. "Windows"

gebruik 'n XPath navraag //configuration/system.web/authentication[mode]?

protected void Page_Load(object sender, EventArgs e)
{
 XmlDocument config = new XmlDocument();
 config.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
 XmlNode node = config.SelectSingleNode("//configuration/system.web/authentication");
 this.Label1.Text = node.Attributes["mode"].Value;
}
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top