[img]http://wpa.qq.com/pa?p=1:155169851:11[/img][url=tencent://message/?uin=155169851&Site=Oscar&Menu=yes]点击这里给我发消息[/url]

如何获取当前ASP.NET应用的认证模式

Posted on 2006-04-30 10:25  づ韓じ懷飛→  阅读(322)  评论(0编辑  收藏  举报
NET 1.1里,

using System.Configuration;
using System.Web.Configuration;
using System.Reflection;


public AuthenticationMode GetAuthenticationMode()
{
 object auth = ConfigurationSettings.GetConfig("system.web/authentication");
 if (auth!= null)
 {
 //an internal class "System.Web.Configuration.AuthenticationConfig"
 Type t = auth.GetType();
 PropertyInfo pi = t.GetProperty("Mode",BindingFlags.Instance|BindingFlags.NonPublic);
 return (AuthenticationMode)pi.GetValue(auth,null);
  }

  return AuthenticationMode.None;
}


.NET 2.0里,

using System.Configuration;
using System.Web.Configuration;

public AuthenticationMode GetAuthenticationMode()
{
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

        SystemWebSectionGroup swsg = (SystemWebSectionGroup)config.GetSectionGroup("system.web");

        AuthenticationSection auth = swsg.Authentication;
 return auth.Mode;
}

Copyright © 2024 づ韓じ懷飛→
Powered by .NET 8.0 on Kubernetes