Asp.net ';http://www.domain.con/Image.jpg' 不是有效的虚拟路径

Asp.net ';http://www.domain.con/Image.jpg' 不是有效的虚拟路径,asp.net,vb.net,Asp.net,Vb.net,在subdomain.domainname中,我有一个通用处理程序,它应该从domainname Dim Path As String = "http://www.domainname/" context.Response.ContentType = "image/jpg" context.Response.WriteFile(Path & ImgName & ".jpg") 问题是我无法添加物理路径,因为response.WriteFile接受物理路径。我得到了有效的虚拟路径

subdomain.domainname
中,我有一个通用处理程序,它应该从
domainname

Dim Path As String = "http://www.domainname/"
context.Response.ContentType = "image/jpg"
context.Response.WriteFile(Path & ImgName & ".jpg")
问题是我无法添加物理路径,因为response.WriteFile接受物理路径。我得到了有效的虚拟路径错误

那么,当图像存在于
domainname
中,并且我的通用处理程序位于
子域.domainname
时,如何加载图像呢

有什么窍门我可以用吗


我不想将处理程序移动到
域名

为什么不将请求重定向到非子域

Dim Path As String = "http://www.domainname/"
context.Response.ContentType = "image/jpg"
context.Response.WriteFile(Path & ImgName & ".jpg")
context.Response.Redirect(Path & ImgName & ".jpg")

您可以先下载映像,然后将缓冲区写入响应:

Using client = New WebClient()
    ' This assumes that http://www.domainname.com/ returns a JPEG image
    Dim file As Byte() = client.DownloadData("http://www.domainname.com/")
    context.Response.ContentType = "image/jpg"
    Dim filename = Path.ChangeExtension(imgFile, "jpg")
    context.Response.AppendHeader("Content-Disposition", "inline; filename=" & filename);
    context.Response.OutputStream.Write(file, 0, file.Length)
End Using

我只是在这里抛开了显而易见的问题,但您是否错过了顶级域,即
.com


http://www.mydomain.com/

@Maras我现在不知道这个外壳是如何工作的,但它确实可以!关于这些信息,你能指出一个有趣的链接吗?谢谢所有这一切都是向浏览器发送一个请求图像的响应,告诉浏览器从传递到
响应的路径中检索图像,而不是从子域中检索图像。重定向
。您始终可以将指向域名称图像的路径直接放在配置中并执行写文件。在每次请求时重定向站点上的每个图像资产是一个更好的解决方案。