Handle PermanentRedirects in PrerenderTagHelpers (#7179)
Handle PermanentRedirects in PrerenderTagHelpers
This commit is contained in:
parent
e3e9b120b3
commit
28b56587b1
|
|
@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||||
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
|
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
|
||||||
public PrerenderTagHelper(IServiceProvider serviceProvider)
|
public PrerenderTagHelper(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
var hostEnv = (IHostingEnvironment) serviceProvider.GetService(typeof(IHostingEnvironment));
|
var hostEnv = (IHostingEnvironment)serviceProvider.GetService(typeof(IHostingEnvironment));
|
||||||
_nodeServices = (INodeServices) serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
|
_nodeServices = (INodeServices)serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
|
||||||
_applicationBasePath = hostEnv.ContentRootPath;
|
_applicationBasePath = hostEnv.ContentRootPath;
|
||||||
|
|
||||||
var applicationLifetime = (IApplicationLifetime) serviceProvider.GetService(typeof(IApplicationLifetime));
|
var applicationLifetime = (IApplicationLifetime)serviceProvider.GetService(typeof(IApplicationLifetime));
|
||||||
_applicationStoppingToken = applicationLifetime.ApplicationStopping;
|
_applicationStoppingToken = applicationLifetime.ApplicationStopping;
|
||||||
|
|
||||||
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
||||||
|
|
@ -102,7 +102,8 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
||||||
if (!string.IsNullOrEmpty(result.RedirectUrl))
|
if (!string.IsNullOrEmpty(result.RedirectUrl))
|
||||||
{
|
{
|
||||||
// It's a redirection
|
// It's a redirection
|
||||||
ViewContext.HttpContext.Response.Redirect(result.RedirectUrl);
|
var permanentRedirect = result.StatusCode.GetValueOrDefault() == 301;
|
||||||
|
ViewContext.HttpContext.Response.Redirect(result.RedirectUrl, permanentRedirect);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue