asp.net application-level authentication users are logged on to general handlers _ practical Tips

Source: Internet
Author: User
You should all want to have an application-level simple process, today just be asked, so simply write down the code, the following steps:

1, create a class library project, named Ihandlers, name customization
2, in the class library project to add "ASP." NET handler, named HandleSession.cs. Open this file and add a reference:

Using System.Web.SessionState
Let the Handlesession class inherit the interface ireadonlysessionstate.
The above two steps are to allow you to use the Session object.
The complete code for the class is as follows:
Copy Code code 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 in your Web site.
and register this handler with IIS before you can use it. For more information,
See the link below: http://go.microsoft.com/?linkid=8101007
</summary>
#region IHttpHandler Members
public bool IsReusable
{
Returns False if the managed handler cannot be reused for another request.
This is usually false if some state information is retained on request.
get {return true;}
}
public void ProcessRequest (HttpContext context)
{
Your handler implementation is written here.
if (context. session["UID"] = = null)
{
Context. Response.Redirect ("http://www.baidu.com");
}
}
#endregion
}
}


In fact, is to judge if the session object does not exist to jump to Baidu home page.
3, compile the class library project, build the DLL, add a reference to this DLL in the site
4, register this handler in the web.config of the website, add the following line of code in
Copy Code code as follows:


<add verb= "*" path= "temp/*.aspx" type= "ihandlers.handlesession, ihandlers"/>


Path: Specifies all *.aspx files under the/temp folder in the root directory
Type: namespace name. class name, assembly name
For more parameter descriptions please refer to Microsoft MSDN
After this is done, a generic handler is triggered when the user accesses an ASPX file under the Temp folder.
Anti-Theft chain, anti-download can 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.