Author Top Nguyen
Elect.Web.Middlewares contain many utility middlewares to help you monitor your application.
- CorsMiddleware: Configuration cross-origin requestp policy.
- HttpContextMiddleware: Help you can access
HttpContext
of the Http Request in any layer. - MeasureProcessingTimeMiddleware: Auto Start
Stopwatch
when receive a Http Request and End when finish Http Response. - MinResponseMiddleware: Auto minify HTML, CSS and JS content when response.
- RequestRewindMiddleware: Enable Rewind for Http Request, useful if you want to read Request Body content.
- ServerInfoMiddleware: Add Server Information, useful to Client have author contact and server information. You can fake this information to improve your system security.
- Package Manager
PM> Install-Package Elect.Web.Middlewares
- .NET CLI
dotnet add package Elect.Web.Middlewares
-
Almost Middleware have Extensions for
IApplicationBuilder
andIServiceCollection
. -
CorsMiddleware
- Add Service:
services.AddElectCors()
- You can configuration by parameterElectCorsOptions
. - Use Middleware:
app.UseElectCors()
. - Use: This middleware auto verify
HttpRequest
and append Headers forHttpResponse
about Cors Information.
- Add Service:
-
HttpContextMiddleware
- Add Service:
services.AddElectHttpContext()
.(CorsMiddleware/Models/ElectCorsOptions.cs) - Use Middleware:
app.UseElectHttpContext()
. - Use: You can access
HttpContext
of currentHttpRequest
by static objectHttpContext.Current
- using namespaceElect.Web.Middlewares.HttpContextMiddleware
.
- Add Service:
-
MeasureProcessingTimeMiddleware
- Use Middleware:
app.UseElectMeasureProcessingTime()
. - Use: This middleware auto append Headers for
HttpResponse
keyX-Processing-Time-Milliseconds
about total milliseconds for handle the request.
- Use Middleware:
-
MinResponseMiddleware
- Add Service:
services.AddElectMinResponse()
. - Use Middleware:
app.UseElectMinResponse()
. - Use: This middleware auto minify HTML, CSS and JS content when response.
- Add Service:
-
RequestRewindMiddleware
- Use Middleware:
app.UseElectRequestRewind()
. - Use: This middleware auto enable Request Rewind every
HttpRequest
, you can read raw HttpRequest Body.
using (var ms = new MemoryStream(2048)) { await Request.Body.CopyToAsync(ms); var contentBytes = ms.ToArray(); }
- Use Middleware:
-
ServerInfoMiddleware
- Add Service:
services.AddElectServerInfo()
- You can configuration by parameterElectCorsOptions
. - Use Middleware:
app.UseElectServerInfo()
. - Use: This middleware auto append Headers for
HttpResponse
about Server Info.
- Add Service:
-
GCCollectMiddleware
- Use Middleware:
app.UseGCCollect()
. - Use: This middleware auto call GC Collect when response.
- Use Middleware:
Elect.Web.Middlewares is licensed under the MIT License.