ASP. NET application-level verification of user logon to General handlers

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.