Using Context.RewritePath to rewrite to another domain

This is my first post on SO. :) My goal is that in the application (which is the existing shake of the VB.NET application) whenever a request is encountered for a resource, for example:

/itemimages/image.png 

So that he texted on

 http://example.com/itemimages/image.png 

There are 10 GB of images in the workplace, so for local development we just want to rewrite the request so that we do not have to upload and mix about 10 GB of product images.

I tried the following in Application_BeginRequest () to remember that I am simplifying this to illustrate the problem I am facing:

 If (url1.IndexOf("itemimages") > 0) Then Dim app As HttpApplication = CType(sender, HttpApplication) app.Context.RewritePath("https://www.google.com/images/srpr/logo3w.png") End If 

The error I am getting is:

'https: /www.google.com/images/srpr/logo3w.png' is not a valid virtual path.

Note the single slash at https: /www.google.com, although I have provided two slashes. In addition, he explicitly mentions that this is not a valid VIRTUAL path, so I cannot specify an absolute URL here.

How can I rewrite requests to "/itemimages/image.png" to "http://www.website.com/itemimages/image.png"? I post this in C # also because I like this language more and maybe can easily convert any solution between the two.

+4
source share
1 answer

Context.RewritePath processes the request in a different way using ASP.Net.
It does not make sense to do with an external server.

You want Response.Redirect .

+2
source

All Articles