How to generate a dynamic javascript or css file using ASP.NET Core Razor engine
Available in
English (English)
asp.net-core
javascript
css
.net
dynamic-resource
dynamic-javascript
dynamic-css
Someday I wanted to push out of my cshtml most of the javascript and css styles. However I faced an issue when I needed to customize a bit the css or the javascript for a specific user, cookie value etc.
This article explains how you can easily include a dynamic javascript file (or dynamic css), by using the power of the razor engine and cshtml files.
Read
How to implement a custom base class for razor views in ASP.NET Core
Available in
English (English)
asp.net-core
razor-library
razor
Not well known practice and not well documented but quite powerful: it is possible to override the base class of the views and pages in order to share a same logic or just to simplify some calls within views.
Read
How to inject HttpContext or ActionContext ?
Available in
English (English)
asp.net-core
Few tools from the ASP.NET Core framework may be quite useful, but you should use the proper way to access them. This way is not always obvious, and knowing about it makes all the difference.This post explains how to allow injection of HttpContext and ActionContext in another injected class.
Read
How to extract daily stats as a weekly calendar using T-SQL
Available in
English (English)
tsql
sql server
When you are a bit into SQL, logging and statistics, you may want to extract some statistics from your logs.
While a group by easily outputs a list of stats per date, when looking at a single indicator, you may be more confortable to see stats grouped per week to isolate seasonality of the week. This articles shows how to output such a table from a log with SQL Server.
Read
Building ASP.NET Core web projects using razor libraries
Available in
English (English)
c#
asp.net-core
Since the ASP.NET Core 2.1 release, it became finally easy to implement independent web libraries embedding everything it needs to set up a feature.This post is the first of a serie, that intends to explain how to set an ASP.NET Core razor MVC library to be used as an independent plugin.Such a lib is autonomous, can be packaged in a NuGet and activated just by refencing this project.
Read
Dynamically pre-load assemblies in a ASP.NET Core (or any C#) project
Available in
English (English)
c#
asp.net-core
This article explains how to preload some assemblies for a .Net project and provides all the code required to replicate the behavior.
Read
How to Include static files in a Razor library
Available in
English (English)
asp.net-core
razor-library
embedded-files
static-files
embedded-static-files
wwwroot
Razor libraries are a great improvement for splitting the development of ASP.NET Core projects into projects, however it still lacks (v2.1) the possibility to easily include static files in libraries, such as images, CSS or javascript files, fonts or web libraries.
This posts explains the principle allowing to include static files in a Razor Library for folders of type /wwwroot or /Areas/Feature/wwwroot
Read
Generate a HTML string from cshtml razor view using ASP.NET Core that can be used in the c# controller code
Available in
English (English)
asp.net-core
.net
html
c#
viewtostring
renderview
render-view-as-string
In several occasions, I needed a way to output the result of cshtml views as a string. Some day, I wanted a partial view that I could embed in a JSON response, another time it was to build an email template.
For this, we need a feature that is mostly implemented with the Razor engine, but that is not publicly available (yet).
In this article, you will discover how to build an efficient ViewToString renderer and get directly access to the HTML generated by a cshtml view.
Read
Introduction post!
Available in
English (English)
- français (French)
blog
This is a short introduction article to this blog
Read
How to enable CORS for POST requests on a single endpoint in ASP.NET Core
Available in
English (English)
asp.net-core
This article explains a way to enable CORS requests for a single endpoint in ASP.NET Core, without using the official middleware. It has been made to add flexibility to the way CORS is handled.
Read
How to automatically embed static files in ASP.NET Core libraries and Razor libraries
Available in
English (English)
asp.net-core
razor-library
c#
embedded-files
static-files
embedded-static-files
Have you ever dreamed of embedding everything required for a specific feature in a dedicated library? This article will teach you how to embed automatically your static files in an ASP.NET Core library.
We have seen how to manually include static files in a razor library, this post will go even further and provide a way to do this automatically. Here you will find how to discover libraries that embed static files and include them automatically to serve them with the static file middleware.
Read