Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

SSR & does not append headers. #1335

Closed
rohan-buechner opened this issue Oct 13, 2017 · 2 comments
Closed

SSR & does not append headers. #1335

rohan-buechner opened this issue Oct 13, 2017 · 2 comments

Comments

@rohan-buechner
Copy link

I have an Isomorphic white-labelled app of sorts that needs to be able to differentiate its data by means of supplying a header to each request. EG:

We'll be able to spawn up a new web app & api for a type of product, but then by means of some clever proxy work, we want to be able to expose a web app to different countries via a host name change of sorts. (This difference is required to segregate data at the back end)

1. www.web.foo.usa.com 
2. www.web.foo.za.com

The API

1. www.api.foo.com

I have an endpoint that looks like this:

 public string search(string text)
 {
     StringValues foo = "";
     if (Request.Headers.TryGetValue("Origin", out foo))
     {
        Console.WriteLine(foo.ToString());
     }
     
     return "bar";
 }

When doing a regular Ajax fetch from my front end app, I will see a log entry in the console that matches my origin.

www.web.foo.za.com    // thus this was a successful log

BUT..

On the very first request (on server pre-render), or when I disable javascript (no ajax)/ cache clear & hard reload (pre-render again), Origin seems to be empty... even though the request is successful. (Meaning the ServerSideRenderer completed the request).

Wireshark, seems to confirm my suspicions...

Regular request:
AJAX REQUEST

SSR Request:
SSR

Question:

When SSR is taking place, how do I detect the actual origin of the request?

@rohan-buechner rohan-buechner changed the title SSR & does not append Origin header. SSR & does not append headers. Oct 13, 2017
@SteveSandersonMS
Copy link
Member

When SSR is taking place, how do I detect the actual origin of the request?

If the browser chooses not to send an Origin header, there's nothing SSR can do to change that - the request has already been sent. In general you should not expect all requests to have Origin headers (see info).

Normally if you're working with a reverse proxy, it will be possible to configure the reverse proxy to attach the original URL as an extra header, but you'll need to see docs for your reverse proxy about how to do that (or even implement it yourself, if you have created your own reverse proxy).

Then you can pass through that extra header into your SSR code using the asp-prerender-data tag helper.

@rohan-buechner
Copy link
Author

@SteveSandersonMS I literally (about an hour ago), found the asp-prerender-data tag on another question you answered ... this was exactly what I needed, and allowed me to solve/progress from my roadblock. Thank you :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants