TheBeerHouse 系列二:web.config的魅力
2007-05-12 12:48
417 查看
这个跟以前~~介绍过的Web设置 类似,只是这里的Web设置更好点- -先看下web.config片断
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="theBeerHouse" type="MB.TheBeerHouse.TheBeerHouseSection, __code"/>
</configSections>
<theBeerHouse defaultConnectionStringName="LocalSqlServer">
<contactForm mailTo="thebeerhouse@wrox.com"/>
<!--默认显示商品的数量-->
<articles pageSize="10" />
<polls archiveIsPublic="true" votingLockByIP="false" />
<newsletters fromEmail="thebeerhouse@wrox.com" fromDisplayName="TheBeerHouse" />
<forums threadsPageSize="8" hotThreadPosts="10" bronzePosterPosts="10" silverPosterPosts="20" goldPosterPosts="50" />
<store sandboxMode="true" businessEmail="thebeerhouse@wrox.com" />
</theBeerHouse>
开始- -分析首先是 <section name="theBeerHouse" type="MB.TheBeerHouse.TheBeerHouseSection, __code"/>Web设置 讲过了~~就是对应一个类.
<theBeerHouse defaultConnectionStringName="LocalSqlServer">.....</theBeerHouse>这个是跟上面name对应的节点Web设置也有详细说明~~不废话~~首先看看类图然后再分析下哪里不同咯
public class TheBeerHouseSection : ConfigurationSection
public class ContactFormElement : ConfigurationElement
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/AccessDenied.aspx" name="TBHFORMAUTH"/>
</authentication>
上面这段代码有意思,他的作用是结合权限验证的如果没有经过权限验证则定位到某某页,其实我更倾向于下面这样写利用HttpHandler来自动捕捉
public class Bt : IHttpHandlerFactory
>
<httpHandlers><!--verb是处理的请求类型*是所有,GET,POST, PATH=处理的类型,typehttpHandLers-->
<add verb="*" path="*.aspx" type="Bt"/>
</httpHandlers>
---跑题了我们继续-说说Web事件~`首先看个类
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Management;
namespace MB.TheBeerHouse
<healthMonitoring heartbeatInterval="10800" >//针对运行状况监视配置应用程序,必选的 TimeSpan 属性。
//heartbeatInterval指定时间间隔,即引发 WebHeartbeatEvent 事件的频率(以秒为单位)。 默认值为 "00:00:00",它表示不引发 WebHeartbeatEvent 事件。
<providers>
<remove name="SqlWebEventProvider" />
<add name="SqlWebEventProvider" connectionStringName="LocalSqlServer"//buffer定义提供程序的缓冲功能。
buffer="false" bufferMode="Notification" maxEventDetailsLength="1073741823"//bufferMode定义提供程序的缓冲功能。
type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<eventMappings>//可选的元素。将事件友好名称映射到相关的事件类型。
<add name="TBH Events" type="MB.TheBeerHouse.WebCustomEvent, MB.TheBeerHouse.CustomEvents" />
</eventMappings>
<rules>
<clear />//就是可以触发检测的程序配置--SqlWebEventProvider这个是值得记录到Sql中--记录Window到日志中--EventLogWebEventProvider
<add name="TBH Events" eventName="TBH Events" provider="SqlWebEventProvider" profile="Critical" />
<add name="All Errors" eventName="All Errors" provider="SqlWebEventProvider" profile="Critical" />
<add name="Failure Audits" eventName="Failure Audits" provider="SqlWebEventProvider" profile="Critical" />
<add name="Heartbeats" eventName="Heartbeats" provider="SqlWebEventProvider" profile="Critical" />
</rules>
</healthMonitoring>
//--------------。与内置的 ASP.NET 运行状况监视事件不同的是,自定义事件必须显式引发。
要引发自定义事件必须
RecordDeletedEvent swre =new RecordDeletedEvent ("Heartbeats", this, myCode);//--参数1是eventName
// --运行这个引发自定义事件
swre.Raise();
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="theBeerHouse" type="MB.TheBeerHouse.TheBeerHouseSection, __code"/>
</configSections>
<theBeerHouse defaultConnectionStringName="LocalSqlServer">
<contactForm mailTo="thebeerhouse@wrox.com"/>
<!--默认显示商品的数量-->
<articles pageSize="10" />
<polls archiveIsPublic="true" votingLockByIP="false" />
<newsletters fromEmail="thebeerhouse@wrox.com" fromDisplayName="TheBeerHouse" />
<forums threadsPageSize="8" hotThreadPosts="10" bronzePosterPosts="10" silverPosterPosts="20" goldPosterPosts="50" />
<store sandboxMode="true" businessEmail="thebeerhouse@wrox.com" />
</theBeerHouse>
开始- -分析首先是 <section name="theBeerHouse" type="MB.TheBeerHouse.TheBeerHouseSection, __code"/>Web设置 讲过了~~就是对应一个类.
<theBeerHouse defaultConnectionStringName="LocalSqlServer">.....</theBeerHouse>这个是跟上面name对应的节点Web设置也有详细说明~~不废话~~首先看看类图然后再分析下哪里不同咯
public class TheBeerHouseSection : ConfigurationSection
public class ContactFormElement : ConfigurationElement
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/AccessDenied.aspx" name="TBHFORMAUTH"/>
</authentication>
上面这段代码有意思,他的作用是结合权限验证的如果没有经过权限验证则定位到某某页,其实我更倾向于下面这样写利用HttpHandler来自动捕捉
public class Bt : IHttpHandlerFactory
>
<httpHandlers><!--verb是处理的请求类型*是所有,GET,POST, PATH=处理的类型,typehttpHandLers-->
<add verb="*" path="*.aspx" type="Bt"/>
</httpHandlers>
---跑题了我们继续-说说Web事件~`首先看个类
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Management;
namespace MB.TheBeerHouse
<healthMonitoring heartbeatInterval="10800" >//针对运行状况监视配置应用程序,必选的 TimeSpan 属性。
//heartbeatInterval指定时间间隔,即引发 WebHeartbeatEvent 事件的频率(以秒为单位)。 默认值为 "00:00:00",它表示不引发 WebHeartbeatEvent 事件。
<providers>
<remove name="SqlWebEventProvider" />
<add name="SqlWebEventProvider" connectionStringName="LocalSqlServer"//buffer定义提供程序的缓冲功能。
buffer="false" bufferMode="Notification" maxEventDetailsLength="1073741823"//bufferMode定义提供程序的缓冲功能。
type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<eventMappings>//可选的元素。将事件友好名称映射到相关的事件类型。
<add name="TBH Events" type="MB.TheBeerHouse.WebCustomEvent, MB.TheBeerHouse.CustomEvents" />
</eventMappings>
<rules>
<clear />//就是可以触发检测的程序配置--SqlWebEventProvider这个是值得记录到Sql中--记录Window到日志中--EventLogWebEventProvider
<add name="TBH Events" eventName="TBH Events" provider="SqlWebEventProvider" profile="Critical" />
<add name="All Errors" eventName="All Errors" provider="SqlWebEventProvider" profile="Critical" />
<add name="Failure Audits" eventName="Failure Audits" provider="SqlWebEventProvider" profile="Critical" />
<add name="Heartbeats" eventName="Heartbeats" provider="SqlWebEventProvider" profile="Critical" />
</rules>
</healthMonitoring>
//--------------。与内置的 ASP.NET 运行状况监视事件不同的是,自定义事件必须显式引发。
要引发自定义事件必须
RecordDeletedEvent swre =new RecordDeletedEvent ("Heartbeats", this, myCode);//--参数1是eventName
// --运行这个引发自定义事件
swre.Raise();
相关文章推荐
- TheBeerHouse 系列一(这是个什么咚咚)
- TheBeerHouse 系列四:从表示层开始下(我怎样限制你的自由??)
- TheBeerHouse 系列三:从表示层开始上
- C#进阶系列——使用Advanced Installer制作IIS安装包(一:配置IIS和Web.config)
- config the Cache in the file of Web.Config
- 搜索引擎早期重要论文推荐系列【7】《Searching the Web》
- .NET错误The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
- TheBeerHouse 网站项目学习笔记(3)----安全管理(上)
- The web.config file for this project is missing the required DirectRequestModule.
- 开始学习TheBeerHouse
- TheBeerHouse 网站项目学习笔记(5)---架构设计
- The difference between Web.config and App.config.
- 艾伟_转载:VS 2010 和 .NET 4.0 系列之《干净的Web.Config文件 》篇
- 【zt】PWS、TheBeerHouse、PetShop 4.0、DNN学习收藏整理
- unix&linux系列二:WebApps' config & security by irunnet.com
- C#进阶系列——使用Advanced Installer制作IIS安装包(一:配置IIS和Web.config)
- How to Modify the web.config file in SharePoint using SPWebConfigModification?
- Configuring ASP.NET AJAX in the web.config
- 为什么TheBeerHouse的网站可以VS2005下正常编译通过?
- IBatis.Net系列 - Invalid SqlMap.config document. cause :Cannot load schema for the namespace ''