File tree Expand file tree Collapse file tree
server/src/Docs.Web/Middleware Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,22 +3,15 @@ namespace Docs.Web.Middleware;
33/// <summary>
44/// Middleware that serves a custom 404.html page when the response status code is 404.
55/// </summary>
6- public class NotFoundMiddleware : IMiddleware
6+ public class NotFoundMiddleware ( IWebHostEnvironment environment ) : IMiddleware
77{
8- private readonly IWebHostEnvironment _environment ;
9-
10- public NotFoundMiddleware ( IWebHostEnvironment environment )
11- {
12- _environment = environment ;
13- }
14-
158 public async Task InvokeAsync ( HttpContext context , RequestDelegate next )
169 {
1710 await next ( context ) ;
1811
1912 if ( context . Response . StatusCode == 404 && ! context . Response . HasStarted )
2013 {
21- var notFoundPath = Path . Combine ( _environment . WebRootPath , "404.html" ) ;
14+ var notFoundPath = Path . Combine ( environment . WebRootPath , "404.html" ) ;
2215
2316 if ( File . Exists ( notFoundPath ) )
2417 {
Original file line number Diff line number Diff line change @@ -3,20 +3,13 @@ namespace Docs.Web.Middleware;
33/// <summary>
44/// Middleware that redirects old URLs to new destinations using a preloaded redirect map (301 permanent).
55/// </summary>
6- public class RedirectMiddleware : IMiddleware
6+ public class RedirectMiddleware ( IReadOnlyDictionary < string , string > redirectMap ) : IMiddleware
77{
8- private readonly IReadOnlyDictionary < string , string > _redirectMap ;
9-
10- public RedirectMiddleware ( IReadOnlyDictionary < string , string > redirectMap )
11- {
12- _redirectMap = redirectMap ;
13- }
14-
158 public async Task InvokeAsync ( HttpContext context , RequestDelegate next )
169 {
1710 var path = context . Request . Path . Value ? . TrimEnd ( '/' ) ?? "" ;
1811
19- if ( _redirectMap . TryGetValue ( path , out var destination ) )
12+ if ( redirectMap . TryGetValue ( path , out var destination ) )
2013 {
2114 var queryString = context . Request . QueryString . HasValue ? context . Request . QueryString . Value : "" ;
2215 context . Response . StatusCode = 301 ;
You can’t perform that action at this time.
0 commit comments