Preventive chain download issues
I often put things around the network, sometimes I'm touching a copy there is a similar
Http://193.100.100.56/testwebsolut ... TION1 / TEST.RAR Address is ready to download the test.rar file, but notified that there is no login or directly to other pages, then wait until the login downloads the file directly. To achieve the above situation, it is easier in the .NET world.
1. First create a class library project Classlibrary1, as follows (click here):
Using system;
Using system.Web; // Reference System.Web Components
Namespace Classlibrary11
{
Public class myhandler: IHTTPHANDLER
{
Public myHandler ()
{
}
#Region Ihttphandler member
Public void processRequest (httpcontext context)
{
// Jump to WebForm1.aspx, output the RAR file by Webform1.aspx
HttpResponse response = context.response;
Response.Redirect ("
http://193.100.100.56/testwebsolution/ ... /webform1.aspx ");
}
Public Bool IsReusable
{
get
{
// Todo: Add myHandler.Isreusable getter implementation
Return True;
}
}
#ndregion
}
}
2. Create a Web project WebApplication1 for testing. Add the following nodes in the configuration file Web.config file node:
Httphandlers>
3. Add a text to "Download" in WebForm1.aspx, and its Click event is as follows (click here):
FileInfo file = new system.io.fileinfo (@ "g: /webcenter/testwebsolution/webapplication1/test.rar");
// FileInfo class in the system.io namespace
Response.clear ();
Response.addheader ("Content-Disposition", "FileName =" file.name);
Response.addheader ("Content-Length", File.length.toString ());
String fileextension = file.extension;
/ / According to the file suffix specified the MIME type of the file
Switch (FileExtension)
{
Case ".mp3":
Response.ContentType = "Audio / MPEG3";
Break;
Case "MPEG":
Response.contentType = "video / mpeg";
Break;
Case "JPG":
Response.ContentType = "image / jpeg";
Break;
Case "........":
Response.contentType = "....";
Break;
DEFAULT:
Response.contenttype = "Application / OcTet-stream";
Break;
}
Response.writefile (file.fullname);
Response.end ();
4. The last step is to add an application extension in IIS. In the "default website" -> "Properties" -> "Proterly" -> Configuration. Press "Add" in the "Application Configuration" window that pops up, "Execute File" in the "Add / Edit Application Extension Mapping" window in the pop-up window Select C: /Windows / Microsoft.Net/framework/v1.1.4322 /ASPNET_ISAPI.DLL, enter ".rar" in the extension, then OK.
5, enter in IE
http://193.100.100.56/testwebsolution/webapplication1/test.rar, will immediately jump to
http://193.100.100.56/testwebsolut ... at1 / WebForm1.aspx, then follow the WebForm1.aspx "Download" button to download Test.rar.
6. Of course, here only give a thinking, it can be expanded according to its own situation. Here are a few reference resource articles:
http://www.9seek.com/news/show.aspx?id=745&cid=12
http://www.9seek.com/news/show.aspx?id=521&cid=12
http://www.9seek.com/news/show.aspx?id=520&cid=12
Http://msdn.microsoft.com/asp.net/using/building/web/defa ... en-us / dnaspp / html / urlrewriting.asp