Handle PermanentRedirects in PrerenderTagHelpers (#7179)

Handle PermanentRedirects in PrerenderTagHelpers
This commit is contained in:
Ryan Brandenburg 2019-02-05 09:22:40 -08:00 committed by GitHub
parent e3e9b120b3
commit 28b56587b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
public PrerenderTagHelper(IServiceProvider serviceProvider)
{
var hostEnv = (IHostingEnvironment) serviceProvider.GetService(typeof(IHostingEnvironment));
_nodeServices = (INodeServices) serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
var hostEnv = (IHostingEnvironment)serviceProvider.GetService(typeof(IHostingEnvironment));
_nodeServices = (INodeServices)serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
_applicationBasePath = hostEnv.ContentRootPath;
var applicationLifetime = (IApplicationLifetime) serviceProvider.GetService(typeof(IApplicationLifetime));
var applicationLifetime = (IApplicationLifetime)serviceProvider.GetService(typeof(IApplicationLifetime));
_applicationStoppingToken = applicationLifetime.ApplicationStopping;
// 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))
{
// It's a redirection
ViewContext.HttpContext.Response.Redirect(result.RedirectUrl);
var permanentRedirect = result.StatusCode.GetValueOrDefault() == 301;
ViewContext.HttpContext.Response.Redirect(result.RedirectUrl, permanentRedirect);
return;
}
@ -123,4 +124,4 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
}
}
}
}
}