WebConfigurationManager.AppSettings
WebConfigurationManager.ConnectionStrings
或者时候1.1里面老的方式实现IConfigurationSection,其实都无所谓了。
这里主要讨论一下使用ConfigurationSection抽象类的方式,定义配置节,可以实现多配置节,其实和IConfigurationSection一样,没感觉有什么很大区别。做个笔记而已了
首先web.config
<configSections>2
<section name="mqtest" type="test, __code"/>3
</configSections>4
<mqtest>5
<aaForm asdfa="10"></aaForm>6
</mqtest>
2
/// <summary>3
/// 配置节的访问4
/// </summary>5
public class test : ConfigurationSection6
{7
//元素8
[ConfigurationProperty("aaForm", IsRequired = true)]9
public aaFormElement aaForm10
{11
get { return (aaFormElement)base["aaForm"]; }12
}13

14
[ConfigurationProperty("time")]15
public DateTime Time16
{17
get { return (DateTime)this["time"]; }18
set { this["time"] = value; }19
}20

21
[ConfigurationProperty("tt")]22
public int tt23
{24
get { return (int)this["tt"]; }25
set { this["tt"] = value; }26
}27

28
public override bool IsReadOnly()29
{30
return false;31
}32
}33

34
///配置节文件中的配置元素35
public class aaFormElement : ConfigurationElement36
{37

38
[ConfigurationProperty("asdfa", DefaultValue = "10")]39
public string aaaa40
{41
get { return (string)base["asdfa"]; }42
set { base["asdfa"] = value; }43
}44
}45

test Settings1 = (test)WebConfigurationManager.GetSection("mqtest");
Settings1.tt = 100;==============直接取属性
<system.web>
<httpRuntime maxRequestLength="4096" executionTimeout="120" ></httpRuntime>
</system.web>
Configuration config = WebConfigurationManager.OpenWebConfiguration(this.Request.ApplicationPath);HttpRuntimeSection myHttpRuntimeSection = (HttpRuntimeSection)config.GetSection("system.web/httpRuntime");
demo
网站分为前台后后台管理页面,一般前台部设置用户访问权限,任何用户都可访问,但后台必须是注册用户才能登陆。
【IIS 验证机制】
Asp.net验证分为两步。首先,IIS验证当前用户访问网站所使用的windows帐号是否有权限。如果IIS访问被配置为anonymous,则任何用户都能访问页面。
然后,在IIS验证完毕后,ASP.net开始执行自身的验证。验证模式可以在web.config文件中配置,只要在config文件中写上<authentication mode="Forms" />,那么ASP.net就知道使用FormsAuthenticationModule 类进行验证。
【Forms Authentication 控制流程】
第一步:用户访问default.aspx页面,IIS通过了验证,ASP.Net发现
authorization元素中包含<deny users="?" />的标签。
第二步:服务器寻找包含验证信息的cookie,如果没有找到这个cookie,用户将被重定向到登陆页面。就是loginurl所指定的页面。用户将在那个页面输入登陆信息。
第三步:浏览器请求浏览登录页面,同时传递ReturnUrl的参数的值。
第四步:服务器调转到登陆页面。
第五步:用户输入身份验证信息,并且提交数据,其中还包含ReturnUrl的参数值。
第六部:服务器通过读取存储介质(例如sqserver数据库)验证用户的信息。登陆页面将创建一个包含FormAuthentication ticket的cookie作为session。
第七步:用户验证成功,服务器重新让浏览器指向ReturUrl所指定的页面。
第八步:在重定向的同时,浏览器向default.aspx页面发送request请求,此次请求包含用户的forms authentication cookie。
第九步:FormsAuthenticationModule类侦测到forms authentication cookie并且开始验证,验证成功后,该类将得到当前的用户信息,并传送给HttpContext对象。可以通过HttpContext对象获得当前用户的信息。
第10步:验证成功
Demo




