Skip to content

Commit 1be9102

Browse files
Prerendering server-side code can now issue redirections. Fixes aspnet#280
1 parent c2c45b0 commit 1be9102

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/Microsoft.AspNetCore.SpaServices/Prerendering/PrerenderTagHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
8585
unencodedPathAndQuery,
8686
CustomDataParameter,
8787
TimeoutMillisecondsParameter);
88+
89+
if (!string.IsNullOrEmpty(result.RedirectUrl))
90+
{
91+
// It's a redirection
92+
ViewContext.HttpContext.Response.Redirect(result.RedirectUrl);
93+
return;
94+
}
95+
96+
// It's some HTML to inject
8897
output.Content.SetHtmlContent(result.Html);
8998

9099
// Also attach any specified globals to the 'window' object. This is useful for transferring

src/Microsoft.AspNetCore.SpaServices/Prerendering/RenderToStringResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public class RenderToStringResult
66
{
77
public JObject Globals { get; set; }
88
public string Html { get; set; }
9+
public string RedirectUrl { get; set; }
910
}
1011
}

0 commit comments

Comments
 (0)