[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 づ韓じ懷飛→ 阅读(178) 评论(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;
}

posts - 20, comments - 25, trackbacks - 0, articles - 1

Copyright © づ韓じ懷飛→