I'm trying to redirect from inside a MVC controller to a different external URL, only adding a session cookie that I'd be able to access after redirection.
I've been checking tens of Stackoverflow's questions and more, only found old or irrelevant answers, or with different technologies.
// GET: api/lem/fst?url=xxx
[HttpGet]
public ActionResult Get([FromQuery]string url)
{
var uri = new UriBuilder(url);
var cookieOptions = new CookieOptions
{
Domain = uri.Host,
};
HttpContext.Response.Cookies.Append("key123", "value123", cookieOptions);
return Redirect(uri.ToString());
}
For example, if I send a GET to https://.../api/lem/fst?url=www.google.com, I can see the cookie in the Set-Cookie response header from my server. Also, redirection works fine, while I can't see the cookie anywhere in the request or response from google.
Thanks!