Response.Redirectを使用して.datファイルをダウンロードするようにユーザーがコードしています。 しかし、常にこのエラーが表示されます。ダウンロード.datファイルのコード
The page you are requesting cannot be served because of the extension
configuration. If the page is a script, add a handler. If the file should be
downloaded, add a MIME map.
のResponse.Redirect
Response.Redirect(filepath, false);
のための私のサンプルコードでは、私は何もしていないことの何が問題になって。さらに、このコードを使用して.xlsxファイルをダウンロードできます。
私を助けてくれてありがとう。
これはダウンロードする応答がない更新されたコードです。
EDITED CODE
string fpath = Server.MapPath("data") + "\\" + filename + ".dat";
if (File.Exists(fpath))
{
File.Delete(fpath);
}
StreamWriter swExtLogFile = new StreamWriter(fpath, true);
try
{
int i;
foreach (DataRow row in tbl.Rows)
{
object[] array = row.ItemArray;
for (i = 0; i < array.Length - 1; i++)
{
swExtLogFile.Write(array[i].ToString());
}
swExtLogFile.WriteLine(array[i].ToString());
}
swExtLogFile.Close();
swExtLogFile.Dispose();
FileInfo fInfo = new FileInfo(fpath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", fInfo.Length.ToString());
Response.AppendHeader("content-disposition",
string.Format("attachment;filename={0}", fInfo.Name));
Response.Flush();
Response.TransmitFile(fInfo.FullName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
MIMEタイプを追加するにはIISでチェックしましたか? – Jacky
["拡張設定のために要求しているページを配信できません]の重複している可能性があります。エラーメッセージ](https://stackoverflow.com/questions/4388066/the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configura) – BACON