如何解决System.Web.HttpException:不是有效的虚拟路径

时间:2014-07-23 08:30:52

标签: asp.net vb.net

我正在使用 ASP.Net (VB.net)开发网站,@特定阶段执行以下代码

Private Sub btndownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndownload.Click
   Response.ContentType = "application/pdf"
   Response.TransmitFile(hdndownload.Value) ' http:/localhost/sample_web/sample.pdf is the value for hdndownload.Value
End Sub

但它导致如下错误:

Server Error in '/sample_web' Application.
http://localhost/sample_web/sample.pdf' is not a valid virtual path.
An unhandled exception occurred during the execution of the current web request. 
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: 'http:/localhost/sample_web/sample.pdf' is not a valid virtual path.

1 个答案:

答案 0 :(得分:0)

如果你对hdndownload.value的评论中的值是正确的,那么你就错过了/

传递的值应为

http://localhost/sample_web/sample.pdf 
      ^

不是

http:/localhost/sample_web/sample.pdf