国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼

來源:懂視網 責編:小采 時間:2020-11-27 22:42:26
文檔

驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼

驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼:如果我們能更好地掌握這樣一個過程,那么對單個ASP.NET Page的生命周期也能更好地了解: 下面介紹如何編寫一個簡單的ASP.NET 頁面和一個簡單的HttpModule,對MSDN里提到的ASP.NET的生命周期進行驗證 1. 首先使用Visual Studio 2010建立一個
推薦度:
導讀驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼:如果我們能更好地掌握這樣一個過程,那么對單個ASP.NET Page的生命周期也能更好地了解: 下面介紹如何編寫一個簡單的ASP.NET 頁面和一個簡單的HttpModule,對MSDN里提到的ASP.NET的生命周期進行驗證 1. 首先使用Visual Studio 2010建立一個

如果我們能更好地掌握這樣一個過程,那么對單個ASP.NET Page的生命周期也能更好地了解:
下面介紹如何編寫一個簡單的ASP.NET 頁面和一個簡單的HttpModule,對MSDN里提到的ASP.NET的生命周期進行驗證
1. 首先使用Visual Studio 2010建立一個空的ASP.NET網站 (ASP.NET 4.0)
2. 添加一個Default.aspx,添加三個ASP.NET控件,分別為TextBox,Button和Validator:
代碼如下:  
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="OK" onclick="btnSubmit_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please input your name!" ControlToValidate="txtName" ForeColor="#FF3300">
</asp:RequiredFieldValidator>
</div>
</form>

3. 添加一個ASP.NEt的App_code文件夾,新建一個類,內容為:
代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class TestClass : IHttpModule
{
HttpApplication httpApp;
public static List<string> EventList = new List<string>();
public TestClass()
{
}
public void Dispose()
{ }
public void Init(HttpApplication context)
{
this.httpApp = context;
//EventList.Clear();
EventList.Add("Initiated");
context.BeginRequest += new EventHandler(context_BeginRequest);
context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
context.ResolveRequestCache += new EventHandler(context_ResolveRequestCache);
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
context.PostReleaseRequestState += new EventHandler(context_PostReleaseRequestState);
context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
context.UpdateRequestCache += new EventHandler(context_UpdateRequestCache);
context.EndRequest += new EventHandler(context_EndRequest);
}
private void context_EndRequest(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: End Request <hr>");
foreach (string str in EventList)
{
httpApp.Response.Write(str + "<br>");
}
EventList.Clear();
}
void context_UpdateRequestCache(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Update Request Cache");
}
void context_ReleaseRequestState(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Release Request State");
}
void context_PostReleaseRequestState(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Post Release Request State");
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Pre Request Handler Execution");
}
void context_AcquireRequestState(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Acquire Request State");
}
void context_ResolveRequestCache(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Resolve Request");
}
void context_AuthorizeRequest(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Authorize Request");
}
void context_AuthenticateRequest(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: AuthenticateRequest");
}
void context_BeginRequest(object sender, EventArgs e)
{
EventList.Add("HTTP Modules: Begin Request");
}
}

4. 修改剛才的Default.aspx的后臺cs代碼:
代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init()
{
TestClass.EventList.Add("ASP.NET Page: Page_Init");
}
protected void Page_Load(object sender, EventArgs e)
{
TestClass.EventList.Add("ASP.NET Page: Page_Load");
}
public override void Validate()
{
TestClass.EventList.Add("ASP.NET Page: Validated");
base.Validate();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
TestClass.EventList.Add("ASP.NET Page: Event");
}
protected override void Render(HtmlTextWriter writer)
{
TestClass.EventList.Add("ASP.NET Page: Render");
base.Render(writer);
}
protected void Page_Unload(object sender, EventArgs e)
{
TestClass.EventList.Add("ASP.NET Page: Unload");
}
}

5. 修改web.config內容如下:
代碼如下:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.web>
<httpModules>
<add name="TestClass" type="TestClass"/>
</httpModules>
</system.web>
</configuration>

6. Ctrl+F5執行,在瀏覽器里可以看到:

7. 在文本框內輸入內容,可得:

 
結論:
1. Module只初始化了一次,當頁面postback的時候,module不會再初始化。
2. Validate和Event事件在頁面第一次初始化的時候不會觸發,但是由于頁面本身存在validate控件和事件按鈕,所以這兩個事件在第二次會被觸發。
本文參考了codeproject.com的如下一篇文章http://www.codeproject.com/KB/aspnet/ASPDOTNETPageLifecycle.aspx

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼

驗證一個ASP.NET應用程序和頁面的生命周期的實現代碼:如果我們能更好地掌握這樣一個過程,那么對單個ASP.NET Page的生命周期也能更好地了解: 下面介紹如何編寫一個簡單的ASP.NET 頁面和一個簡單的HttpModule,對MSDN里提到的ASP.NET的生命周期進行驗證 1. 首先使用Visual Studio 2010建立一個
推薦度:
標簽: 頁面 代碼 周期
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 国产美女一区二区 | 台湾一级毛片永久免费 | 在线观看网站国产 | 另类专区另类专区亚洲 | 亚洲欧洲日韩在线 | 亚洲国产婷婷综合在线精品 | 亚洲图片欧美日韩 | 久久久久久久国产高清 | 欧美日韩亚洲一区二区三区在线观看 | 国产一区二区三区视频在线观看 | 欧美色图亚洲激情 | 欧美日韩国 | 日韩欧美高清 | 久久国产精品高清一区二区三区 | 亚洲第一页在线观看 | 亚洲欧美精品伊人久久 | 国产精品一区二区手机在线观看 | 国产精品久久久久免费 | 免费精品国产日韩热久久 | 日韩精品免费观看 | 日本欧美国产精品第一页久久 | 亚洲欧美二区三区久本道 | 亚洲欧美日韩精品永久在线 | 精品国产一区二区三区不卡蜜臂 | 国产午夜视频在线观看 | 国产欧美一区二区精品性色 | 亚洲欧美日韩另类在线专区 | 亚洲另类中文字幕 | 国产99久久 | 爱色电影 | 国内偷拍第一页 | 久久久久成人精品一区二区 | 国产高清美女一级a毛片久久 | 国产精品亚洲精品日韩动图 | 亚洲va欧美va天堂v国产综合 | 欧美在线观看视频免费 | 成人毛片在线播放 | 91精品啪在线观看国产线免费 | 可以免费看的毛片 | 欧美精品午夜久久久伊人 | 免费观看a黄一级视频 |