Custom processing page request

xiaoxiao2021-03-05  34

Mainly inherit IHTTPModule and IHTTPHAndler to override the method in which IHTTPModule is renovated in INIT method and various requesting process events and Dispose methods.

Using

System.Web;

Using

System;

Namespace

Customerhttpmodules

{/ ** ////

/// Class1 Summary Description. /// public class MyHttpModules: IHttpModule {public MyHttpModules () {} IHttpModule member #region IHttpModule members void System.Web.IHttpModule.Init (HttpApplication context) {context.BeginRequest = new EventHandler (context_BeginRequest); context. EndRequest = new EventHandler (this.context_EndRequest);} public void context_BeginRequest (object obj, System.EventArgs e) {HttpApplication app = (HttpApplication) obj; app.Response.Write ( "Hi, testing customer http module request"); } public void context_EndRequest (object obj, System.EventArgs e) {HttpApplication app = (HttpApplication) obj; app.Response.Write ( "Hi, end request here");} public void Dispose () {// TODO: Add MyHttpModules .Dispose implementation} #ENDREGON}}

Then generate a DLL, new ASP.NET application, reference this DLL, join in Web.config

This DLL is found when there is a page request and then executes the process.

-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------

The following is the code to override the Chinese method in IHTTPHANDAL:

Built a class library

Using

System;

Using

System.Web;

Namespace

Customerhttphandler

{/ ** ////

/// Class1 Summary Description. /// public class TestCustomerHttpHandler: IHttpHandler {public TestCustomerHttpHandler () {// // TODO: Add constructor logic here //} IHttpHandler member #region IHttpHandler members public void ProcessRequest (HttpContext context) {context. Response.Write ( "hi, I write something instead of what you input");} public bool IsReusable {get {// TODO: Add TestCustomerHttpHandler.IsReusable getter achieve return true;}} #endregion}} core processing all pages of referrals It is done through the ProcessRequest method of IHTTPHANDLER, so as long as we rewrite this method, no matter any request, it will be replaced by the content we have rewritten.嘿嘿

Add to Web.config in the ASP.NET application after generating DLL

Look at the effect

转载请注明原文地址:https://www.9cbs.com/read-33655.html

New Post(0)