Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将路径映射到不同的域_C#_Asp.net_Redirect - Fatal编程技术网

C# 将路径映射到不同的域

C# 将路径映射到不同的域,c#,asp.net,redirect,C#,Asp.net,Redirect,我希望能够将路径映射到不同的域,但在地址栏中保留原始地址。是否有方法对此进行编码,或者是在IIS中进行编码。如果可能的话,我最好想要一个编码的方法 我有一个链接,其href如下“http://www.example.com/invproxy.aspx?id=1&batch=1". 我想要那张地图“http://www.otherdomain.com/Files/TheFileRequest.aspx“ 我使用原始请求的查询字符串生成要映射到的路径。它与Server.Transfer或Respon

我希望能够将路径映射到不同的域,但在地址栏中保留原始地址。是否有方法对此进行编码,或者是在IIS中进行编码。如果可能的话,我最好想要一个编码的方法

我有一个链接,其href如下“http://www.example.com/invproxy.aspx?id=1&batch=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);

编辑:为了添加完成的结果,我在浏览器中的一个新选项卡中显示了我的PDF文档(在兼容的地方),地址栏上写着

,根据上面的回答,我建议使用加载,将您实际想要的页面加载到您希望最终用户看到其URL的页面中。请记住,这可能会产生连锁反应,具体取决于所包含页面的复杂程度。

尝试以下方法:

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);

。。你可以让它更复杂。。如果有必要,只是向您展示如何在当前URL中检索查询字符串参数和值

otherdomain.com是否位于同一台服务器上,或者您是否以其他方式控制它?是的,它们都在我的VPS上运行,我控制它们。我可能不太理解您100%的意图,但是,这种技术应该为您提供当前URLOk的各个部分,所以让它稍微复杂一点,实际提供的内容将是PDF文档。对于没有内置PDF查看器的浏览器来说,这不是一个问题,因为文件将只是下载而不是在页面中打开。但对于支持它的浏览器,我想显示PDF,但URL如上所示。我在我的链接上使用target=“\u blank”,因此始终会打开一个新选项卡。这应该仍然有效,但如果这是您试图完成的全部任务,那么您可以将内容类型更改为application/pdf,并将pdf字节流式传输到响应。这里有一个关于如何做流媒体的链接:PDF通常可以通过3种方式提供给用户。。。使用PDFViewer.aspx。。您将字节(也称为PDF文件)发送给用户。。为文件本身提供扩展名为*.pdf的HTTP处理程序。。。或者将PDFViewer嵌入到一个对象中——作为严格的HTML(或者iframe——过渡HTML)。。如果您需要示例,每个示例我都有一些,但它们在VB.NET中。。虽然有一个工具可以很容易地获得C语言的代码,但多亏了Chris Shain和MacGyver先生,我已经能够得到我的答案。我将更新我的帖子以显示我正在使用的代码。