我希望能够将路径映射到不同的域,但保留地址栏中的原始地址。有没有一种方法来编码或在IIS中。如果可能的话,我最好喜欢一种编码方法。映射到不同域的路径
我有一个链接,其href是这样的“http://www.example.com/invproxy.aspx?id=1 &批= 1”。 我想要那张地图到“http://www.otherdomain.com/Files/TheFileRequest.aspx”。
我生成的映射路径使用原始请求的查询字符串。它适用于Server.Transfer或Response.Redirect但我想要地址栏仍然说最初请求的URL。这可能吗?
感谢
编辑:我已经解决了这个问题(可能不是最经济的方式),但下面是我使用的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);
编辑的Page_Load事件的代码:只需添加完成的结果,我得到我的PDF文档显示在浏览器中的新标签(在兼容)与地址栏说http://www.example.com/invproxy?myquerystring
是否otherdomain.com住在如何检索当前URL查询字符串参数和值同一台服务器,还是你控制它? –
是的,他们都在我的VPS上运行,我控制他们两个。 –
我可能并不完全理解你正在尝试做什么,但是这种技术应该会给你目前的URL – MacGyver