Dot Net Stories

asp.net-core c# .net javascript xamarin

Articles about .Net, ASP.NET Core, Xamarin, Javascript, CSS This site is powered by a blog engine built on ASP.NET Core, HTML, Boostrap and jQuery

en

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.
en

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.
en

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.
en

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.
en

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
en

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.
en

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.