バックエンド コード Handler.ashx
<%@ WebHandler Language= "C#" Class="Handler" %>
using System;
public class Handler: IHttpHandler {
public void ProcessRequest ( HttpContext context) {
string fileName = "web.config";//クライアントによって保存されたファイル名
string filePath = context.Server.MapPath("web.config");//Path
/ / ファイルを文字ストリームとしてダウンロードします
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
byte[] bytes = new byte[( int) fs.Length];
fs.Close();
context.Response.ContentType = "アプリケーション/オクテットストリーム"; 🎜> //ファイルを開くのではなくダウンロードするようにブラウザに通知します
context.Response.AddHeader("Content-Disposition", "attachment; filename=" HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) );
context.Response.BinaryWrite(bytes);
context.Response.End();
public bool {
get {
return false;
}
}
}
フロントエンドコード:
コードをコピーします
< head>
<script> <br>function download_file(url) <br>{ <br><br>if (typeof (download_file.iframe) == "未定義") <br>{ <br>var iframe = document .createElement("iframe"); <br>download_file.iframe = iframe; <br>document.body.appendChild(download_file.iframe);アラート(download_file.iframe); <br> download_file.iframe.src = url; <br><br>download_file.iframe.style.display = "なし"; <br><br><br><br>} <br></script>
aaaaa bbbbb ccccc 🎜>