IIS prevents file downloads from full manual (non-change filename method)

Source: Internet
Author: User
iis| filename | Download the IHttpHandler
Problem: Prevent all Files under Encry directory from being illegally downloaded
Solution:
1, Overview: Applying the Application Mappings in IIS to IHttpHandler custom permissions in asp.net
The IIS application mappings are used to simply put all the files, and give control to our own implementation of the IHttpHandler

2, to achieve:
2.1 Add Application Mappings: Open IIS Manager-> right-click the site we want to control download-> "Configure ..." in the Properties dialog box.

Change the file in the red circle to your own. NETFramework aspnet_isapi.dll Path

2.2 Modify Web.config Add HttpHandlers item under system.web
<system.web>
...

<add verb= "*" path= "encry/*.*" type= "Customhttphandler.class1,customhttphandler" ></add>

...
</system.web>
2.3 Implementation IHttpHandler

------------------------File:Class1.cs---------
Using System;
Using System.Web;
Namespace Customhttphandler
{
<summary>
Summary description of the CLASS1.
</summary>
public class Class1:System.Web.IHttpHandler
{
Public Class1 ()
{
//
TODO: Add constructor logic here
//
}
#region IHttpHandler Members

public void ProcessRequest (HttpContext context)
{
TODO: Add class1.processrequest implementation
String Strrefurl=context. request.servervariables["Http_referer"];
/* Insert your own code, read the contents of the file and populate the response, this example simply returns an error message * *
Context. Response.Write ("You cannot access this page");
}

public bool IsReusable
{
Get
{
TODO: Add class1.isreusable Getter Implementation
return false;
}
}

#endregion
}
}
-----------------File:end------------------------------------------------




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.