I often put things around the network, sometimes I'm touching a copy there is a similar
http://193.100.100.56/testwebsolution/webapplication1/test.rar Address When you are ready to download the Test.rar file, it is notified that there is no login or directly jump to other pages, and then download the file directly after logging in. 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/webapplication1/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 http://193.100.100.56/testwebsolution/webapplication1/test.rar in IE, will immediately jump to http://193.100.100.56/testwebsolution/webapplication1/webform1.aspx, then press Webform1.aspx " Download the 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:
l http://www.9seek.com/news/show.aspx?id=745&cid=12
l http://www.9seek.com/news/show.aspx?id=521&cid=12
l http://www.9seek.com/news/show.aspx?id=520&cid=12
l http://msdn.microsoft.com/asp.net/using/building/web/default.aspx?pull=/library/en-us/dnaspp/html/urlrewriting.asp