Passing session data (or any data) from Node.js to .NET Core in prerender #1475

Closed
opened 2025-08-09 17:20:17 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @mgroger on 7/26/2016

I see that in the prerender the JS script returns html and globals in JSON to .NET Core, which then adds that content to the appropriate spots in the HTML template.

I'm trying to understand if there's any way to use any of that returned data in .NET Core directly instead of just outputting to HTML.

My specific example: I'd like to use some of the returned data to set a client cookie with session data. I want to call a different backend in my SPA that currently uses sessions for authentication. If I set a cookie with the session ID for this different backend, then if the user reloads the prerender can use the cookie to pass the same session ID on to the other server for requests.

Perhaps this will make more sense with an example:

  1. First Request - Render on server, call login or whatever other page is requested. Return session token(s) as part of each response from server, represents current session.
    • Session token is saved in prerendered globals for use by client, goes to Redux store to be used in subsequent requests.
    • ALSO set session information in cookie, sent back to client. How would this session information get from Node.js to .NET Core to be set as cookie on prerender server? This is where I'm getting stuck.
  2. Client side can then pass the same session ID when calling backend.
  3. When rendering on server again, check for session ID saved in cookie, pass if exists.

Thanks!

*Originally created by @mgroger on 7/26/2016* I see that in the prerender the JS script returns html and globals in JSON to .NET Core, which then adds that content to the appropriate spots in the HTML template. I'm trying to understand if there's any way to use any of that returned data in .NET Core directly instead of just outputting to HTML. My specific example: I'd like to use some of the returned data to set a client cookie with session data. I want to call a different backend in my SPA that currently uses sessions for authentication. If I set a cookie with the session ID for this different backend, then if the user reloads the prerender can use the cookie to pass the same session ID on to the other server for requests. Perhaps this will make more sense with an example: 1. First Request - Render on server, call login or whatever other page is requested. Return session token(s) as part of each response from server, represents current session. - Session token is saved in prerendered globals for use by client, goes to Redux store to be used in subsequent requests. - ALSO set session information in cookie, sent back to client. How would this session information get from Node.js to .NET Core to be set as cookie on prerender server? This is where I'm getting stuck. 2. Client side can then pass the same session ID when calling backend. 3. When rendering on server again, check for session ID saved in cookie, pass if exists. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1475
No description provided.