-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VP-558 middlewar for giving index when 404
- Loading branch information
1 parent
ec1fe2d
commit 39f648f
Showing
2 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
VirtoCommerce.Storefront/Middleware/SpaFallbackMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace VirtoCommerce.Storefront.Middleware | ||
{ | ||
// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project | ||
public class SpaFallbackMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public SpaFallbackMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
|
||
await _next.Invoke(context); | ||
|
||
if (!context.Response.HasStarted && context.Response.StatusCode == (int)HttpStatusCode.NotFound) | ||
{ | ||
//context.Response.Redirect("home/index"); | ||
context.Request.Path = "/"; | ||
await _next.Invoke(context); | ||
} | ||
|
||
} | ||
} | ||
|
||
// Extension method used to add the middleware to the HTTP request pipeline. | ||
public static class SpaFallbackMiddlewareExtensions | ||
{ | ||
public static IApplicationBuilder UseSpaFallbackMiddleware(this IApplicationBuilder builder) | ||
{ | ||
return builder.UseMiddleware<SpaFallbackMiddleware>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters