您的位置:首页 > 其它

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: