Ответ 1
Попробуйте Context.User.Identity.AuthenticationType
Пойдите для людей, отвечающих за PB
Скажем, у меня есть следующий web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authentication mode="Windows"></authentication>
</system.web>
</configuration>
Используя ASP.NET С#, как я могу определить значение режима тега проверки подлинности?
Попробуйте Context.User.Identity.AuthenticationType
Пойдите для людей, отвечающих за PB
Свойство 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
}
Вы также можете получить режим аутентификации, используя статический ConfigurationManager
класс, чтобы получить раздел, а затем перечисление AuthenticationMode
.
AuthenticationMode authMode = ((AuthenticationSection) ConfigurationManager.GetSection("system.web/authentication")).Mode;
Разница между WebConfigurationManager и ConfigurationManager
Если вы хотите получить имя константы в указанном перечислении, вы можете сделать это, используя метод Enum.GetName(Type, Object)
Enum.GetName(typeof(AuthenticationMode), authMode); // e.g. "Windows"
использовать запрос xpath//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;
}