System. Io. fileinfo info = new system. Io. fileinfo (server. mappath ("data \") + "filename.exe ");
Protected void button3_click (Object sender, eventargs E)
{
Response. Clear ();
Response. clearheaders ();
Response. Buffer = true;
// Specify a stream that cannot be read by the client and must be downloaded.
Response. contenttype = "application/octet-stream ";
// Add the header information and specify the default file name for the "download/Save as" dialog box
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (info. Name, system. Text. encoding. utf8 ));
// Add header information and specify the file size so that the browser can display the download progress.
Response. addheader ("Content-Length", info. length. tostring ());
// Response. addheader ("content-transfer-encoding", "binary ");
// Specify a stream that cannot be read by the client and must be downloaded.
// Response. addheader ("Content-Type", "application/X-msdownload ");
// Specify a stream that cannot be read by the client and must be downloaded.
// Response. contenttype = "application/MS-excel ";
// Send the file stream to the client
Response. writefile (info. fullname );
Response. Flush ();
Response. End ();
}
File Download, specifying the default name
Response. addheader ("Content-Type", "application/X-msdownload ");
Response. addheader ("content-disposition", "attachment?filename=file name to be downloaded. rar ");
Refresh page
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 Orientation
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 box
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 unbuffered
Response. expires = 0
Response. expiresabsolute = now ()-1
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-control", "private"
Response. cachecontrol = "no-Cache"
From: http://hi.baidu.com/jackeyrain/blog/item/afcdc633eeb8b6ff1b4cffd6.html