2011-09-12 47 views
1

subdomain.domainname,我这是为了从domainname的“http://www.domain.con/Image.jpg”是不是有效的虚拟路径

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

问题加载图像的通用处理器我无法添加物理路径,因为Responce.WriteFile接受物理路径。我得到有效的虚拟路径错误。

那么我怎样才能加载图像domainname和我的通用处理程序在subdomain.domainname存在图像?

有什么窍门,我可以使用?

我不想处理程序移动到domainname

+0

您可以始终把路径domainame图像直接在配置,做你的WriteFile的。这是一个更好的解决方案,可以根据每个请求重定向网站上的每个图片资源。 – TheCodeKing

回答

0

为什么不直接将请求重定向到非域名?

context.Response.Redirect(Path & ImgName & ".jpg") 
+0

@Maras我现在不知道这个shell是如何工作的,但它确实如此!你能指出一个有趣的链接,关于这样的信息?谢谢! – OrElse

+0

所有这些都会向请求图像的浏览器发送一个响应,告诉浏览器从传递给'Response.Redirect'的路径中检索图像,而不是从子域中检索图像。 –

2

那么你也可以先下载图像,然后把缓冲区里的响应:

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 
0

我只是抛出了这里显而易见的,但你不是缺少顶级域,即.com

http://www.mydomain.com/

+0

我不拥有.com? :) – OrElse