简体   繁体   中英

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. 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. I need to have a few more I do not want to show in the front-end. An example is a 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.

When you use " RedirectResult ", the new URL is sent back to the browser with a 302 status code. Then the browser makes a 2nd request to download the new 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).

To stop this from happening, your .Net code needs to make the 2nd web request itself. In many cases, you can use the IIS Rewrite module to act as a reverse proxy to do this. If that's doesn't give you enough options, you can make the request yourself by using the WebClient class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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