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

Commit 347524a

Browse files
peterlazzarinoSteveSandersonMS
authored andcommitted
Add status code response capabilities to PrerenderTagHelper and RenderToStringResult. Client can now send status codes back based on client routes.
1 parent b9c387b commit 347524a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
129129
return;
130130
}
131131

132+
if (result.StatusCode.HasValue)
133+
{
134+
ViewContext.HttpContext.Response.StatusCode = result.StatusCode.Value;
135+
}
136+
132137
// It's some HTML to inject
133138
output.Content.SetHtmlContent(result.Html);
134139

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ public class RenderToStringResult
2525
/// to the SPA's routing configuration.
2626
/// </summary>
2727
public string RedirectUrl { get; set; }
28+
29+
/// <summary>
30+
/// If set, specifies the HTTP status code that should be sent back with the server response.
31+
/// </summary>
32+
public int? StatusCode { get; set; }
2833
}
2934
}

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-prerendering/src/PrerenderingInterfaces.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface RenderToStringCallback {
88

99
interface RenderToStringResult {
1010
html: string;
11+
statusCode: number;
1112
globals?: { [key: string]: any };
1213
}
1314

0 commit comments

Comments
 (0)