The following is the definition of the class.
using System; using System.Web; using System.Web.SessionState; namespace QTJZ { public class Filters : IHttpModule, IRequiresSessionState { public void Dispose() { } public void Init(HttpApplication application) { application.AcquireRequestState += new EventHandler(application_AcquireRequestState); } public void application_AcquireRequestState(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; HttpRequest request = application.Request; HttpResponse response = application.Response; string url=request.CurrentExecutionFilePath.Trim('/'); string suffix = request.CurrentExecutionFilePathExtension.Trim('.'); if (!url.Equals("Default.htm") && (suffix == "aspx" || suffix == "htm")) { object sessionObj = application.Context.Session == null ? null : application.Session["useID"]; if (sessionObj==null) { response.Redirect("~/Default.htm"); } } } } }
In order to achieve the filtering effect, the Filters class needs to implement the IHttpMoeld interface. To implement this interface, there are two methods, one is Dispose and the other is Init. The parameter of Init is an instance of HttpApplication type. Use this instance to register some events. Since the URL is now filtered, the AcquireRequestState event is registered. Similar events are listed as follows
#To obtain the url to be redirected, you can use the CurrentExecutionFilePath attribute of the request, and to obtain the suffix of the requested file, you can use the CurrentExecutionFilePathExtension. As for what rules to judge, Depends on demand. What I am doing here is to determine whether the Session exists during the request. If it does not exist, it will jump back to the login page. Since Session is used, an exception will be thrown when opening the page. The exception message is "Session state is not available in this context.". After implementing the IRequiresSessionState interface, no exception will be thrown.
In addition, you also need to add the following code under the
<httpModules> <add name="filters" type="QTJZ.Filters"/> </httpModules>
The type attribute is the fully qualified name of the above Filters class
For more articles related to URL filtering implementation code in ASP.NET, please pay attention to the PHP Chinese website!
This article explores the challenges of NULL pointer dereferences in C. It argues that the problem isn't NULL itself, but its misuse. The article details best practices for preventing dereferences, including pre-dereference checks, pointer initiali

This article explains how to create newline characters in C using the \n escape sequence within printf and puts functions. It details the functionality and provides code examples demonstrating its use for line breaks in output.

This article guides beginners on choosing a C compiler. It argues that GCC, due to its ease of use, wide availability, and extensive resources, is best for beginners. However, it also compares GCC, Clang, MSVC, and TCC, highlighting their differenc

This article emphasizes the continued importance of NULL in modern C programming. Despite advancements, NULL remains crucial for explicit pointer management, preventing segmentation faults by marking the absence of a valid memory address. Best prac

This article reviews online C compilers for beginners, focusing on ease of use and debugging capabilities. OnlineGDB and Repl.it are highlighted for their user-friendly interfaces and helpful debugging tools. Other options like Programiz and Compil

This article compares online C programming platforms, highlighting differences in features like debugging tools, IDE functionality, standard compliance, and memory/execution limits. It argues that the "best" platform depends on user needs,

This article discusses efficient code copying in C IDEs. It emphasizes that copying is an IDE function, not a compiler feature, and details strategies for improved efficiency, including using IDE selection tools, code folding, search/replace, templa

This article troubleshoots missing output windows in C program compilation. It examines causes like failing to run the executable, program errors, incorrect compiler settings, background processes, and rapid program termination. Solutions involve ch


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
