문제

다음 web.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

PB의 답변을 찾아보세요 여러분

다른 팁

인증 섹션의 모드 속성: 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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top