I want to be able to map a path to a different domain but keep the original address in the address bar. Is there a way to code this or is it in IIS. I preferably would like a coded method if possible.
I have a link whose href is like this "http://www.example.com/invproxy.aspx?id=1&batch=1". I want to have that map to "http://www.otherdomain.com/Files/TheFileRequest.aspx".
I generate the path to map to using the querystring of the original request. It works with Server.Transfer or Response.Redirect but i want the address bar to still say the originally requested URL. Is this possible?
Thanks
EDIT: I have solved the issue (probably not the most economical way) but below is the code I am using in the Page_load event of invproxy.aspx
// Just test file, no code to select path yet开发者_如何学运维.
string requestPath = "http://www.otherdomain.com/Files/TestFile.pdf";
// Setup the request for the PDF File
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(requestPath);
// Get the response from otherdomain.com
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
// Assign the invproxy response the PDF ContentType
Response.ContentType = "application/pdf";
// Get the body of the response in a stream object
Stream s = resp.GetResponseStream();
// Create a byte array to be read into from the stream
byte[] buffer = new byte[resp.ContentLength];
int position = 0;
while (true)
{
//Read bytes one by one, slow but causes errors trying to read the whole thing.
//I need to use chunks here.
int b = s.ReadByte();
if (b == -1)
{
//This is the end of the stream
break;
}
else
{
//Set the byte at the current position to the value just read
buffer[position] = (byte)b;
//Advance the position by one.
position++;
}
}
//breakpoint debugging
string sa = Encoding.Default.GetString(buffer);
//Write the file to the invproxy response.
Response.BinaryWrite(buffer);
EDIT: Just to the add the finished result, I get my PDF document displayed in a new tab in the browser (where compatible) with the address bar saying http://www.example.com/invproxy?myquerystring
Based on the response above, I'd suggest using an IFrame to load the page that you actually want inside of the page whose URL you want the end-user to see. Keep in mind, this may have knock-on effects depending on how complex the contained page is.
Try this:
string newParamName = "QueryParam";
string newParamValue = HttpUtility.UrlEncode(Request.QueryString("queryValue").ToString());
Uri uri = HttpContext.Current.Request.Url;
string url = uri.Scheme + "://" + "www.otherdomain.com" + "/Files/TheFileRequest.aspx" + "?" + newParamName + "=" + newParamValue;
HttpContext.Current.Response.Redirect(url);
.. you can make it more sophisticated.. just showing you how to retrieve query string parameters and values in the current URL if necessary
精彩评论