As I've progressed in my usage and understanding of ASP.NET Core, I decided to make me a small support library for shared functionality between projects. From the beginning, I released it as a NuGet package, and while I didn't hide it, I also didn't promote it.
Well, I'm changing that. With the latest release, I feel pretty confident in it and would like to share it with the world. It's called Arex388.AspNetCore (bet you didn't see that coming) and it's currently at version 1.0.11. The source code is available on GitHub and the package is available on NuGet.
AuthenticatedStaticFilesMiddleware
The AutheticatedStaticFiles middleware is a "security" middleware that intercepts requests to static files and checks if the user has been authorized to access the app. If the user is not authorized, then return a 404 response.
public void ConfigureServices(
IServiceCollection services) {
services.Configure<AuthenticatedStaticFileOptions>(
o => {
o.Paths = new List<string> {
"admin.min.js",
"admin.min.css"
};
});
}
public void Configure(
IApplicationBuilder app) {
// ...
app.UseAuthentication();
app.UseAuthenticatedStaticFiles();
app.UseStaticFiles();
// ...
}
FeaturesViewLocationExpander
A view location expander that follows the Vertical slices architecture style by Jimmy Bogard.
public void ConfigureServices(
IServiceCollection services) {
services.AddFeatures();
}
HtmlMinifierMiddleware
A middleware to minify HTML after the Razor view has been rendered using the HtmlAgilityPack.
public void Configure(
IApplicationBuilder app) {
// ...
app.UseHtmlMinifier();
app.UseMvc(...);
// ...
}
SimpleSlugifyParameterTransformer
A parameter transformer to slugify a route value. It is very simple in that it assumes that action names are camel cased, which it then kebaberizes.
public void ConfigureServices(
IServiceCollection services) {
services.Configure<RouteOptions>()
.ConfigureSimpleSlugifyParameterTransformer();
}
SitemapMiddleware
A placeholder middleware to intercept a request for a sitemap and generate one. You will have to implement your own concrete SitemapMiddleware
with your own logic for generating the sitemap. Every app is different so your way of generating the sitemap will vary depending on your data sources.
public void Configure(
IApplicationBuilder app) {
// ...
app.UseSitemap<SitemapMiddleware>();
// ...
}