若需讓下載檔案僅限通過驗證的用戶存取,常見建議是勿置於 Web 根目錄並用 Response.TransmitFile。但若無伺服器存取權,只能將檔放在根目錄。簡單技巧:
myfile.zip 改名為 myfile.config(ASP.NET 禁止直接存取 .config)。if (isValidUser)
{
Response.Clear();
Response.ContentType = "application/setup";
Response.AppendHeader("Content-Disposition", "attachment; filename=myfile.zip");
Response.TransmitFile("myfile.config");
Response.End();
}
利用 ASP.NET 封鎖 .config 副檔名特性,無需伺服器權限即可保護檔案下載。