クエリ文字列を介して渡されたパラメーターに基づいて、Response.WriteFile(fileName) であるリソース ハンドラーがあります。私は MIME タイプを正しく処理していますが、一部のブラウザーでは問題があり、ファイル名は MyPdf.pdf (出力しているファイル) ではなく Res.ashx (ハンドラーの名前) として表示されます。ファイルがサーバーに送り返されたときにファイルの名前を変更する方法を教えてもらえますか? これが私のコードです:
// Get the name of the application
string application = context.Request.QueryString["a"];
string resource = context.Request.QueryString["r"];
// Parse the file extension
string[] extensionArray = resource.Split(".".ToCharArray());
// Set the content type
if (extensionArray.Length > 0)
context.Response.ContentType = MimeHandler.GetContentType(
extensionArray[extensionArray.Length - 1].ToLower());
// clean the information
application = (string.IsNullOrEmpty(application)) ?
"../App_Data/" : application.Replace("..", "");
// clean the resource
resource = (string.IsNullOrEmpty(resource)) ?
"" : resource.Replace("..", "");
string url = "./App_Data/" + application + "/" + resource;
context.Response.WriteFile(url);