Skip to content

Commit

Permalink
Handle PermanentRedirects in PrerenderTagHelpers (#7179)
Browse files Browse the repository at this point in the history
Handle PermanentRedirects in PrerenderTagHelpers
  • Loading branch information
ryanbrandenburg committed Feb 5, 2019
1 parent e3e9b12 commit 28b5658
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class PrerenderTagHelper : TagHelper
/// <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()
Expand Down Expand Up @@ -102,7 +102,8 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
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;
}

Expand All @@ -123,4 +124,4 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
}
}
}
}
}

0 comments on commit 28b5658

Please sign in to comment.