VB.NET服务器端令客户端下载PDF文件

后台JS调用另一个控件,通过SESSION传递sDocumentPath

    控件后台代码如下

   Response.Clear() \'如果不清,则有可能将页面源码作为文件内容的一部分传递给用户

Response.ContentType = "application/pdf" \'下载格式在这里给出

Response.AddHeader("Content-Disposition", "attachment;filename=" & sFileName) \'下载后保存的文件名在此给出

Dim filename As String = Server.MapPath(sDocumentPath) \'Server.MapPath解析文件在服务器上的绝对路径和文件名: 可解析"~/***.**"、"../"等路径前缀

Response.TransmitFile(filename)

Response.End()

    其细节尚一知半解,待以后有时间仔细学习。