检测Web.Config身份验证模式
时间:2020-03-06 14:20:55 来源:igfitidea点击:
说我有以下web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authentication mode="Windows"></authentication>
</system.web>
</configuration>
使用ASP.NET C#,如何检测Authentication标记的Mode值?
解决方案
试试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的引用。
使用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;
}

