ASP.NET開発サーバーでテストすると正常に機能するHttpHandlerを作成しました。
私のWeb.Configには、次のものがあります。
<add verb="*" path="Files.zip" type="MyNamespace.Zip, App_Code" />
そして、App_Codeフォルダーのハンドラーに以下のコードがあります。残念ながら、ASP.NET開発サーバーはすべてをルートにダンプするため、http://localhost:1234/Files.zipは問題なく機能します。ただし、URLがhttp:// myProjects/projectのようなイントラネットサーバーにデプロイしようとしています。ブラウザでhttp://myProjects/project/Files.zipを指定すると、404が表示されます。Web設定を微調整して正しいパスを取得するにはどうすればよいですか。それとも、解決策はどこかにありますか?パスの前に「〜/」と「./」を付けてみました。
(Namespace MyNamespace, file Zip.cs)
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/octet-stream";
DirectoryInfo di = new DirectoryInfo(context.Server.MapPath("files"));
FileInfo[] fileinf = di.GetFiles();
ZipFile zip = new ZipFile();
foreach(FileInfo fi in fileinf)
{
zip.AddFile(fi.FullName, "");
}
zip.Save(context.Response.OutputStream);
}