1

In subdomain.domainname, I have a generic handler which is supposed to load images from the domainname

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

The problem is that i cannot add a physical path, since the Responce.WriteFile accepts a physical path. And i get that valid virtual path error.

So how can i load images when images exist in domainname and my generic handler is at subdomain.domainname?

Is there any trick, i could use?

I do not want to move the handler to the domainname

1
  • You can always put the path to the domainame images directly in the config and do your WriteFile. It's a better solution that redirecting every image asset on the site on every request. Sep 12, 2011 at 20:59

3 Answers 3

2

Well you could download the image first and then write the buffer to the response:

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

Why not just redirect the request to the non-subdomain?

context.Response.Redirect(Path & ImgName & ".jpg")
2
  • @Maras I do not now how the shell this one works, but it sure does! Could you point a interesting link, regarding such info? Thanks!
    – OrElse
    Sep 12, 2011 at 20:32
  • All this does is send a response to the browser requesting the image, telling the browser to, instead of retrieving the image from the subdomain, to retrieve the image from the path passed to Response.Redirect.
    – Adam Maras
    Sep 12, 2011 at 20:54
0

I'm just throwing out the obvious here, but aren't you missing the top-level domain, i.e. .com?

http://www.mydomain.com/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.