Everyone should want an application. Program Simple processing program, just asked today, So I simply wrote Code The procedure is as follows:
1. Create a class library project named ihandlers.
2. Add the ASP. NET handler in the class library project named handlesession. CS. Open this file and add reference:
Using system. Web. sessionstate
Let the handlesession class inherit the ireadonlysessionstate interface.
The above two steps aim to use the session object.
The complete code for this class is as follows: Copy code The Code is as follows: using system;
Using system. Web;
Using system. Web. sessionstate;
Namespace ihandlers
{
Public class handlesession: ihttphandler, ireadonlysessionstate
{
/// <Summary>
/// You will need to configure this handler in the web. config file of your website,
/// Register this handler with IIS before you can use it. For more information,
/// See the following link: http://go.microsoft.com /? Linkid = 8101007
/// </Summary>
# Region ihttphandler members
Public bool isreusable
{
// If the managed handler cannot be reused for other requests, false is returned.
// If some status information is retained as requested, this is usually false.
Get {return true ;}
}
Public void processrequest (httpcontext context)
{
// Write your handler implementation here.
If (context. session ["uid"] = NULL)
{
Context. response. Redirect ("http://www.baidu.com ");
}
}
# Endregion
}
}
In fact, you can jump to the Baidu homepage if the session object does not exist.
3. Compile the class library project, generate the DLL, and add the reference to this DLL to the site.
4. Register this handler in the web. config of the website, and add the following line of code in Copy codeThe Code is as follows: <Add verb = "*" Path = "Temp/*. aspx" type = "ihandlers. handlesession, ihandlers"/>
</Httphandlers>
Path: specifies all *. aspx files in the/Temp folder under the root directory.
Type: namespace name. Class Name, Set Name
For more parameter descriptions, refer to Microsoft msdn
After such processing, a general handler is triggered when you access the aspx file in the temp folder.
Anti-leech protection and anti-download can all be handled in this way.