Http://blog.csdn.net/xzknet/archive/2009/01/05/3710376.aspx
Very useful articles ~!~! When you forget it, you can find it...
File Download, specifying the default nameSrxljl
Response. addheader ("Content-Type", "application/X-msdownload ");
Response.addheader({content-disposition},?attachment=filename=file name to be downloaded. rar ");
Refresh pageSrxljl
Response. addheader "refresh", "60; url = newpath/Newpage. asp"
This is equivalent to the client <meta> element:
<Meta HTTP-EQUIV = "refresh", "60; url = newpath/Newpage. asp"
Page OrientationSrxljl
Response. Status = "302 Object Moved"
Response. addheader "location", "newpath/Newpage. asp"
This is equivalent to using the response. Redirect method:
Response. Redirect "newpath/Newpage. asp"
Force the browser to display a user name/Password dialog boxSrxljl
Response. Status = "401 unauthorized"
Response. addheader "www-authenticate", "basic"
Force the browser to display a user name/Password dialog box, and then send them back to the server using basic verification (the verification method will be seen later in this book ).
How to Make webpages unbufferedSrxljl
Response. expires = 0
Response. expiresabsolute = now ()-1
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-control", "private"
Response. cachecontrol = "no-Cache
Application Instance: File Download
What if Chinese characters are garbled during download?Srxljl
To download files on a website, you just need to click the file link directly. This method has several drawbacks:
1. Some files will not be downloaded and the corresponding program will be called directly to open the file.
2. The actual file address cannot be hidden.
3. The file name cannot be dynamically read from the database for renaming and downloading.
The following is the Asp.net, C # code:
String filename; // name of the file in the database
String dir; // the physical path of the file on the server (for example, C:/AA/DDD/wj1_222.zdo)
Long SIZE; // File Size
Response. addheader ("content-type", "Application/X-msdownload ;");
Response. addheader ("content-disposition", "attachment; filename =" + filename [custom]);
Response. addheader ("Content-Length", size. tostring ());
Response. writefile (Dir, 0, size );
This method can achieve the above purpose, but when the file name (filename) is a Chinese character, garbled characters are displayed on the IE download end. Who knows how to solve this problem.
Let me make a summary.
In fact, the upstairs method is feasible, but it has limitations.
The key lies in the urlencode. The results are different in the following situations.
1. Responseencoding = "gb2312" in Web. config ″
2. Responseencoding = "UTF-8" in Web. config ″
Responseencoding = "UTF-8" is required to use server. urlencode.
So do not use server. urlencode or httputility. urlencode.
String s=httputility.urlencode(system.text.utf8encoding.utf8.getbytes(" 文.txt "));
Response. appendheader ("content-disposition", "attachment; filename =" + S