简体   繁体   English

重定向并在ASP.NET中添加新参数

[英]Redirect and add new parameters in ASP.NET

I have an ASP.NET web controller that receives requests from the front-end and needs to show a web page from another ASP.NET server. 我有一个ASP.NET Web控制器,该控制器从前端接收请求,并且需要显示来自另一个ASP.NET服务器的网页。 So far I have this and it does the simple job of redirecting: 到目前为止,我已经做到了,它完成了重定向的简单工作:

public ActionResult RedirectToAdminPanel(string url)
{
    return new RedirectResult(url);
}

The url contains some parameters and values, which I transfer to the other server. url包含一些参数和值,我将这些参数和值传输到其他服务器。 I need to have a few more I do not want to show in the front-end. 我还需要一些不想在前端显示的内容。 An example is a token . 一个示例是token

I was going to concatenating the url with those hidden values in the method above but I wonder if there is a better way. 我打算在上面的方法中将url与那些隐藏值连接起来,但是我想知道是否有更好的方法。

When you use " RedirectResult ", the new URL is sent back to the browser with a 302 status code. 当您使用“ RedirectResult ”时,新的URL将以302状态代码发送回浏览器。 Then the browser makes a 2nd request to download the new URL. 然后,浏览器发出第二个请求以下载新URL。 This means that the browser will need network connectivity to your 2nd server and the URL in the browser will change to show the new URL (including any token you append). 这意味着浏览器将需要与第二台服务器的网络连接,并且浏览器中的URL将更改为显示新的URL(包括您附加的任何令牌)。

To stop this from happening, your .Net code needs to make the 2nd web request itself. 为了阻止这种情况的发生,您的.Net代码需要自行发出第二个Web请求。 In many cases, you can use the IIS Rewrite module to act as a reverse proxy to do this. 在许多情况下,您可以使用IIS Rewrite模块充当反向代理来执行此操作。 If that's doesn't give you enough options, you can make the request yourself by using the WebClient class. 如果那没有给您足够的选择,您可以使用WebClient类自己提出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM