国产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
主站蜘蛛池模板: 亚洲国产精品欧美日韩一区二区 | 国产大片91精品免费观看不卡 | 青草青99久久99九九99九九九 | 一级黄毛片 | 国产激情在线观看 | 亚洲国产精品综合久久网络 | 亚洲第一页色 | 成人在线一区二区 | 国产视频一区二区在线播放 | 中文字幕精品一区二区精品 | 国产欧美在线观看精品一区二区 | 国产成人高清亚洲一区久久 | 欧美成人国产一区二区 | 久久午夜一区二区 | 久久久一区二区三区 | 高清国产美女一级a毛片 | 国产精品一区二区av | 亚洲欧洲国产经精品香蕉网 | 伊人精品在线视频 | 欧美精品第二页 | 国内精品1区1区3区4区 | 国产一区精品在线 | 日本七十路 | 日本a中文字幕 | 亚洲欧美在线观看 | 日韩欧美高清在线 | 国产精品久久久久999 | 日韩欧美一区二区三区在线 | 日韩在线资源 | 亚洲综合视频 | 我被公睡做舒服爽中文字幕 | 亚洲欧美日韩国产综合高清 | 欧美国产综合在线 | 国产欧美精品综合一区 | 美日韩三级 | 亚洲欧美综合网站 | 成人亚洲国产综合精品91 | 99久久国内精品成人免费 | 一区二区三区不卡视频 | 国产视频一区二区 | 亚洲欧美日本在线 |