Using system; using system. collections. generic; using system. LINQ; using system. web; namespace httphandler {// <summary> // Summary of xiazai1 /// </Summary> public class xiazai1: ihttphandler {public void processrequest (httpcontext context) {context. response. contenttype = "image/JPEG"; // context. response. addheader ("content-disposition", "attachment: filename=haha.jpg"); // you can use the following Asp.net method to add a message header. addheader is an old ASP-compatible method context. response. appendheader ("content-disposition", "attachment: filename=hahaha.jpg"); context. response. writefile ("content/dsc06942.jpg");} public bool isreusable {get {return false ;}}}}
What is the difference between the results and the Web server? Or a browser?
After checking the information, it turns out that a wrong character is entered. You should keep up with the semicolon after the attachment, not the colon!
If you want to change hahaha.jpg to Chinese, you need to encode the Chinese, such
Public void processrequest (httpcontext context) {context. response. contenttype = "image/JPEG"; // context. response. addheader ("content-disposition", "attachment: filename=haha.jpg"); // You can also add a message header using the following Asp.net method, addheader is an old ASP-compatible method string filename = httputility. urlencode ("haha.jpg"); context. response. addheader ("content-disposition", "attachment; filename =" + filename); context. response. writefile ("content/dsc06942.jpg ");}
In this way, you can change the name of an image or other file on the server for the user to download! Everything is under control