Server side rendering window object not rendered #626

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

Originally created by @jeinz11 on 6/28/2017

hi i have this code in my index method and when i check the page source it doesnt have the window object that i assigned in the globals...but when i switch on using the tag helper its perfectly fine i can see the window object

 public async Task<IActionResult> Index()
    {
        var nodeServices = Request.HttpContext.RequestServices.GetRequiredService<INodeServices>();
        var hostEnv = Request.HttpContext.RequestServices.GetRequiredService<IHostingEnvironment>();

        var applicationBasePath = hostEnv.ContentRootPath;
        var requestFeature = Request.HttpContext.Features.Get<IHttpRequestFeature>();
        var unencodedPathAndQuery = requestFeature.RawTarget;
        var unencodedAbsoluteUrl = $"{Request.Scheme}://{Request.Host}{unencodedPathAndQuery}";

        TransferData transferData = new TransferData();
        transferData.Request = AbstractHttpContextRequestInfo(Request); // You can automatically grab things from the REQUEST object in Angular because of this



        // Prerender / Serialize application (with Universal)

        var prerenderResult = await Prerenderer.RenderToString(
            "/", // baseURL
            nodeServices,
            new JavaScriptModuleExport(applicationBasePath + "/ClientApp/dist/boot-server"),
            unencodedAbsoluteUrl,
            unencodedPathAndQuery,
            // Our Transfer data here will be passed down to Angular (within the main.server file)
            // Available there via `params.data.yourData`
            transferData,
            30000,
            Request.PathBase
        );



        // This is where everything is now spliced out, and given to .NET in pieces
        ViewData["SpaHtml"] = prerenderResult.Html;
        if (prerenderResult.RedirectUrl != null)
        {
            return LocalRedirect(prerenderResult.RedirectUrl);
        }

     
        return View();
    }

and in my view

        <div id="react-app">@Html.Raw(ViewData["SpaHtml"])</div>

but no luck i cant see the window object

*Originally created by @jeinz11 on 6/28/2017* hi i have this code in my index method and when i check the page source it doesnt have the window object that i assigned in the globals...but when i switch on using the tag helper its perfectly fine i can see the window object public async Task<IActionResult> Index() { var nodeServices = Request.HttpContext.RequestServices.GetRequiredService<INodeServices>(); var hostEnv = Request.HttpContext.RequestServices.GetRequiredService<IHostingEnvironment>(); var applicationBasePath = hostEnv.ContentRootPath; var requestFeature = Request.HttpContext.Features.Get<IHttpRequestFeature>(); var unencodedPathAndQuery = requestFeature.RawTarget; var unencodedAbsoluteUrl = $"{Request.Scheme}://{Request.Host}{unencodedPathAndQuery}"; TransferData transferData = new TransferData(); transferData.Request = AbstractHttpContextRequestInfo(Request); // You can automatically grab things from the REQUEST object in Angular because of this // Prerender / Serialize application (with Universal) var prerenderResult = await Prerenderer.RenderToString( "/", // baseURL nodeServices, new JavaScriptModuleExport(applicationBasePath + "/ClientApp/dist/boot-server"), unencodedAbsoluteUrl, unencodedPathAndQuery, // Our Transfer data here will be passed down to Angular (within the main.server file) // Available there via `params.data.yourData` transferData, 30000, Request.PathBase ); // This is where everything is now spliced out, and given to .NET in pieces ViewData["SpaHtml"] = prerenderResult.Html; if (prerenderResult.RedirectUrl != null) { return LocalRedirect(prerenderResult.RedirectUrl); } return View(); } and in my view <div id="react-app">@Html.Raw(ViewData["SpaHtml"])</div> but no luck i cant see the window object
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#626
No description provided.