说我有以下web.config:
使用ASP.NET C#,如何检测Authentication标签的Mode值?
身份验证部分的mode属性:AuthenticationSection.Mode属性(System.Web.Configuration).你甚至可以修改它.
// Get the current Mode property. AuthenticationMode currentMode = authenticationSection.Mode; // Set the Mode property to Windows. authenticationSection.Mode = AuthenticationMode.Windows;
本文介绍如何获取AuthenticationSection的引用.
导入System.Web.Configuration
命名空间并执行以下操作:
var configuration = WebConfigurationManager.OpenWebConfiguration("/"); var authenticationSection = (AuthenticationSection)configuration.GetSection("system.web/authentication"); if (authenticationSection.Mode == AuthenticationMode.Forms) { //do something }