Response.WriteFile 可以带有 URL 吗?
我希望能够执行此操作:
Response.WriteFile ("http://domain/filepath/file.mpg")
但是,我收到此错误:
Invalid path for MapPath 'http://domain/filepath/file.mpg'
A virtual path is expected.
WriteFile
方法似乎不适用于 URL。有没有其他方法可以将 URL 的内容写入我的页面?
谢谢。
I would like to be able to do this:
Response.WriteFile ("http://domain/filepath/file.mpg")
But, I get this error:
Invalid path for MapPath 'http://domain/filepath/file.mpg'
A virtual path is expected.
The WriteFile
method does not appear to work with URLs. Is there any other way I can write the contents of a URL to my page?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您需要代码以这种方式工作,那么您必须首先将其动态下载到您的服务器上:
从那时起,您将文件的内容作为流,并且您必须读取/写入字节到响应。
然而,我要提到的是,这不一定是最佳的——您将耗尽带宽,因为每个文件将使用比必要的更多的资源。
如果可能,请将文件移动到您的服务器,或者重新考虑您正在尝试执行的操作。
If you need the code to work in that manner, then you will have to dynamically download it onto your server first:
From that point, you have the contents of the file as a stream, and you will have to read/write the bytes out to the response.
I will mention however, that this is not necessarily optimal--you will be killing your bandwidth, because every file will be using far more resources than necessary.
If possible, move the file to your server, or rethink exactly what you are trying to do.
一个可能的解决方案是简单地使用:
但是,我不确定这是否是您真正想要做的。
A possible solution would be to simply use:
But then, I am not sure if that is what you are really trying to do or not.
基本上你有几个选择。您可以将文件下载到服务器并使用 Response.WriteFile 提供服务,也可以重定向到实际位置。如果该文件已在您的服务器上,您只需提供 Response.WriteFile 的文件系统路径而不是 url,或者通过删除
http://domain< 来使用虚拟 url /代码>。
Basically you have a couple of choices. You can either download the file to your server and serve it with
Response.WriteFile
or you could redirect to the actual location. If the file is already on your server you just have to provide a file system path toResponse.WriteFile
instead of the url, or use a virtual url, by removinghttp://domain
.