質問

言い、次います。config:

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

を使用ASP.NET スレッドセーフで、C#、どのように私を検出するモードの値が認証タグ?

役に立ちましたか?

解決

Context.User.Identity.AuthenticationType

Go PBの答えであ

他のヒント

のモードからプロパティauthenticationsection: AuthenticationSection.モード物件。ます。設定).ともできるので変更することも出来ます。

// 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 クラスを取得し、enum AuthenticationMode.

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

の違いWebConfigurationManagerとConfigurationManager


したい場合に取得する定数の名前で、指定された列挙できないことを利用 Enum.GetName(Type, Object) 方法

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

使用次のようにクエリー//構成/システム。web認証[モード]?

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top