Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • JavaScript • Angular
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

WebLog Posts in Category ASP.NET Core


Categories
ASP.NET (274) .NET (155) JavaScript (72) Windows (70) jQuery (61) ASP.NET Core (56) Visual Studio (54) IIS (48) HTML (47) CSharp (47) AJAX (45) WPF (41) ASP.NET (33) Localization (32) LINQ (30) WCF (28) Personal (26) MVC (26) HTML5 (23) Security (23) FoxPro (22) CSS (21) Angular (20) C# (19) .NET Core (19) Web Services (19) Web Api (16) COM (16) ADO.NET (15) Vista (11) XML (11) Sql Server (10) HTTP (10) IIS7 (10) Markdown (9) Microsoft AJAX (8) WebView (8) West Wind Ajax Toolkit (7) Web Connection (7) IIS7 (7) Internet Explorer (6) Entity Framework (6) Html Help Builder (5) Mobile (5) Markdown Monster (5) ASPNET5 (5) C++ (5) Web (5) Software Development (5) SignalR (5) NuGet (5) Live Writer (5) OWIN (5) WinForms (5) Westwind.Globalization (4) Silverlight (4) Source Control (4) Cordova (4) DataBinding (3) Conferences (3) ISV (3) LetsEncrypt (3) Networking (3) Help Builder (3) Office (3) Opinion (3) Razor (3) Web Browser Control (3) WebLog (3) Visual Studio Code (2) Tools (2) RegEx (2) RSS (2) Speaking (2) Web Development (2) Help (2) Installation (2) Linux (2) ASP.NET vNext (2) Bugs (2) Deployment (2) Dotnet (2) Authentication (2) .NET Standard (2) Addins (2) Visual Studio (1) ADO.NET (1) Blazor (1) Blogging (1) ASP.NET Markdown (1) ASP.NET Security (1) Dynamic Types (1) Email (1) Credit Card Processing (1) Cross-Platform (1) CSharp Dotnet (1) Angular JavaScript (1) Control Development (1) Chocolatey (1) Migration (1) Musings (1) JSON (1) Maui (1) IOS (1) FireFox (1) Flexbox (1) Git (1) Graphics (1) Hardware (1) Windows-Terminal (1) Windsurfing (1) WFH (1) WPF Windows (1) WSL (1) wwHoverPanel (1) Testing (1) Threading (1) SEO (1) rxJs (1) RazorPages (1) Travel (1) Typescript (1) VS Code (1) Web Assembly (1) WebSockets (1) WebSurge (1) WebBrowser (1) WebDeploy (1) Web Deployment Projects (1) Web Design (1)

Back to Basics: Rendering Razor Views to String in ASP.NET Core



Rendering a Razor View to string can be very useful to create string output from Views that you can capture and then use for things like Email confirmations or saved receipts that can be accessed 'offline' from the application. In this post I show you how to capture views to string and a few caveats you have to watch out for if you're generating self-contained HTML output to string.

LiveReloadServer - A Generic Local Static Web Server with Live Reload based on .NET



I've released v1.0 of my LiveReload Web Server which is a local static file Web server that includes support for LiveReload, plus some optional dynamic features for rendering self-contained RazorPages and Markdown content. This Dotnet Tool is fast, easy to use and includes a host of convenience features that try to make the process of working with local Web content quicker and easier.

Role based JWT Tokens in ASP.NET Core APIs



ASP.NET Core Authentication and Authorization continues to be the most filddly part of the ASP.NET Core eco system and today I ran into a problem to properly configure JWT Tokens with Roles. As I had a hard time finding the information I needed in one place and instead ended up with some outdated information, I'm writing up a post to hopefully put all the basic bits into this single post.

Watch out for .NET Core Runtime Bitness for IIS Installs



I recently ran into a snag with one of the my Windows Server installs of an upgraded .NET Core 5.0 application. It turns out I didn't install .NET Core 5.0 correctly because I made some bad assumptions of what I needed to install to run my application, even though it previously ran on .NET Core 3.1. Here's more detail on what the failure looks like and how to properly install .NET Core 5.0.

Upgrading several of my Applications and Libraries to .NET 5.0



Over the last week I spent some time upgrading several .NET Core Web applications and libraries from .NET Core 3.1 to .NET 5.0. I'm happy to say that this was always a non-event as the process went very smooth for once. In this post I'll talk about what I found and also offer some commentary why we should celebrate this update and push Microsoft to continue along this path.

Don't get burned by missing await Calls for Async Code in ASP.NET Core Middleware



I recently got burned in an upgraded ASP.NET Core server application where a missing `await` statement caused wildly inconsistent and puzzling output failures. While a simple thing to avoid, once introduced it's possible to live with this error for some time before it manifests. In this post I show a scenario where a missing `await` was causing infrequent HTTP response errors, even though the client apparently receives a valid response.

Using .NET Core Tools to Create Reusable and Shareable Tools & Apps



Dotnet Tools offer a simple way to create, publish and consume what are essentially .NET Core applications that can be published and shared using the existing NuGet infrastructure for packaging and distribution. It's y quick and easy to build tools that you can share either publicly or privately. In this article I make a case for why you might use or build a Dotnet Tool and show how create, build, publish and consume Dotnet tools as well as showing some examples of useful tools I've build and published.

Handling SPA Fallback Paths in a Generic ASP.NET Core Server



When building ASP.NET Core backends for SPA applications one thing that you have to worry about is how to handle client side routes that end up being fired against the server through external or reloaded links. While ASp.NET Core has built-in support for this if you build a generic Web server, you might need a little more control on how to handle the Fallback routing functionality. Here's how.

Adding Additional Mime Mappings to the Static File Provider



If you're using the Static File Provider in ASP.NET Core you might need to add some additional extensions that are not handled by default. For example, if you host a Blazor site in your own application an additional mime mapping for `.dll` is required. Here how you can map extra extensions to the Static File middleware.

ASP.NET Core WebSockets and Application Lifetime Shutdown Events



WebSockets in ASP.NET Core are easy to use but due to the simple model it's easy to forget that socket requests are long lived and can linger for a long time in the background and that can cause problems when an application needs to shut down cleanly. Luckily there's an `IHostApplicationLifetime` interface available that allows hooking shutdown operations and that provides the necessary cancellation tokens to allow an WebSocket connection to be terminated in response to a shutdown event. This post shows how this works.

Content Injection with Response Rewriting in ASP.NET Core 3.x



If you're creating middleware components you might need at some point to inject content in the existing HTTP output stream in ASP.NET Core. In this post I discuss how to intercept Response output by using a customized stream, modify the data and update the final output generated, effectively providing response filtering.

Back to Basics: Rewriting a URL in ASP.NET Core



Sometimes in an application you need to take over the routing process with some custom processing that acts on an incoming URL and actually has to go to another URL. This can be a simple relinking task from old content to new, or it can be more complex where you access a specific URL on the public site that actually needs to be processed by another URL altogether.

Working with IWebHostEnvironment and IHostingEnvironment in dual targeted ASP.NET Core Projects



In ASP.NET Core 3.x Microsoft introduced a new `IWebHostEnvironment` to replace the obsoleted `IHostingEnvironment`. While that works for top level applications this can cause some complications for multi-targeted libraries that need to support both .NET Core 2.x and 3.x. This post describes the problems and offers a few workarounds.

Null API Responses and HTTP 204 Results in ASP.NET Core



ASP.NET Core's default API handlers return an HTTP 204 response for null value results. This is meant to be a convenience feature, but if your calling API depends on a proper JSON response or an HTTP 200 result code, it can cause applications to break. In this post I'll describe why this can be a problem and how you can return proper JSON results for null values.

ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1



Ran into a nasty little issue with a hosted ASP.NET Core 3.1 application where InProcess hosting was not working. It turns out I hit a regression bug in 3.1 that causes InProcess hosting to fail if there are certain dependencies.

FireFox, Windows Security and Kestrel on ASP.NET Core



Ran into issues today with Windows Authentication and FireFox in a ASP.NET Core application where auth was working with all browsers **except** for FireFox. Firefox would just throw up endless sequences of login dialogs or in some cases just show the default ASP.NET Core 'UnAuthenticated' dialog. Here's what this looks like and how to work around it.

Dynamically Loading Assemblies at Runtime in RazorPages



I've been working on some tools that create generic, standalone Web servers using ASP.NET Core, in various configurations. One of the versions I'm building also supports Razor Pages and while genericallly hosting Razor Pages out of a locally run folder, there are some complications that arise out of dynamic runtime compilation. In this post I look at how to dynamically load assemblies at runtime.

Windows Authentication and Account Caching on Web Browser Auto-Logins



If you're working with Windows authentication to access Windows or Active Directory groups be aware that there's a gotcha with newly added groups when users are automatically logged into the Web browser.

Serving ASP.NET Core Web Content from External Folders



ASP.NET Core makes it easy to create a new Web site, but by default the location of where the application runs and serves files from is pretty static and pinned to the startup folder of the application. In this post I discuss another usage scneario of building a generic local Web Server that can start serving files out of **any** folder.

Upgrading my AlbumViewer Sample Application to ASP.NET Core 3.0



.NET Core 3.0 is here and in this post I describe the process of updating an existing ASP.NET Core Angular API application to this latest release. For the most part the update process is very smooth with a few configuration changes required, but there are also a few gotchas that have bitten me and I'll cover those here.

Building a Live Reload Middleware Component for ASP.NET Core



In my last way I showed how to use Live Reload in ASP.NET Server side applications using a tool called BrowserSync. In this post I replace BrowserSync's functionality with a custom Live Reload Middleware component for ASP.NET Core that's more efficient and doesn't require installing and running a separate tool. I'll show how Live Reload works, and how to implement the component in some detail.

Live Reloading Server And Client Side ASP.NET Core Apps with BrowserSync



Client side live reloading is one of the most compelling features of client side JavaScript development. Instant updates of any code changes in the browser are a huge productivity booster - WYSIWYG on steroids. Unfortunately for ASP.NET Core server side code and MVC apps there aren't any comparable easy solutions. In this post I show how I use Browser Sync and `dotnet watch` in combination to provide live reloading for both server and client side changes.

Accessing RouteData in an ASP.NET Core Controller Constructor



Ran into a difficulty trying to get access to RouteData() generically outside of Controller code in ASP.NET Core. Specifically I needed to get at route data to pull out a tenant ID required to set up a DbContext with the right connection string to connect to. Getting the route data as part of the DI process in the Controller constructor proved to be challenging. In this post I describe the problem and the work around.

ASP.NET Core In Process Hosting on IIS with ASP.NET Core



In version 2.2 ASP.NET Core adds support for direct in-process hosting which improves throughput considerably using an easy mechanism that allows switching between in-process and out-of-process hosting. In this post I describe how to use in process hosting and how it works.

Don't let ASP.NET Core Console Logging Slow your App down



Today I ran into a self-inflicted problem with Console logging while playing with a toy test project. By accident I ran the application under load and Console Logging was on and performance was horrendous. In fact nearly 40x slower horrendous. Although my error, there are a few ways this can happen and it's important to understand that Console logging is very, very slow and in this post I show how this happened and why you want to be careful with Console logging in production.

Updating Westwind.AspnetCore.Markdown with Markdown from Files and URLs



In the last week I've had a need to add some additional features to my Westwind.AspnetCore.Markdown library that provide easier access to Markdown from files and urls as well as the ability to replace the default Markdown parser in the library. In this post I'll discuss some of the feature additions including some implementation notes.

Which .NET Core Runtime Download do you need?



.NET Core has a number of different runtime downloads that you can grab to install. The combinations of downloads can be a bit confusing and it depends on whether you install a development or runtime environment. In this post I describe what each download contains and what you should use it for.

Updating my AlbumViewer to ASP.NET Core 2.1 and Angular 6.0



Took some time to upgrade my AlbumViewer application to ASP.NET Core 2.1 RC and Angular 6.0. The .NET Core update was very smooth with only very minor adjustments required showing that Microsoft has smoothed out the update path significantly from the frenetic pace of past versions. The Angular update was a bit more involved primarily due to the changes in rxJS.

Creating a generic Markdown Page Handler using ASP.NET Core Middleware



I've been talking about Markdown a lot in recent blog posts and this time I'll cover a generic Markdown page handler that you just drop into any site to handle semi-static page editing more easily with Markdown from within an ASP.NET Core application. While Markdown is common fare in CMS or blog applications, it's not so apparent how to get similar generic Markdown document rendering within the context of an existing application. The middleware I describe here allows you to simply drop a markdown file into a configured folder and have it rendered into a stock template. Simple but very useful.

Getting the .NET Core Runtime Version in a Running Application



Microsoft has a long history of not providing a reasonable way of looking up the version of the runtime that is hosting your applications. .NET Core is no different and in this short post I show one way you can capture a descriptive name of the runtime executing that's suitable for displaying in your application's info page.

Creating an ASP.NET Core Markdown TagHelper and Parser



A couple of months ago I wrote about creating a WebForms based Markdown control. This time around I'll build an ASP.NET Core MVC TagHelper that performs similar functionality for embedding Markdown text into a content area of a Razor page. The component also includes easy access to a Markdown parser using the blazing fast MarkDig Markdown parser.

Accessing Configuration in .NET Core Test Projects



.NET Core provides a clean configuration system and in ASP.NET Core that code is automatically configured for you. In test and other non-Web projects however you have to manually configure the configuration provider yourself. In this post I look at a couple of ways to set up a configuration provider both using raw configuration objects or by explicitly configuring through the depedency injection system.

Easy Configuration Binding in ASP.NET Core - revisited



In this post I'm taking another look at using strongly typed configuration settings in ASP.NET Core, using a slightly simpler approach that foregoes using IOptions in favor of directly using a configuration object instance. In the process I review the various approaches as a summary for getting configuration settings into .NET types.

Dev Intersection 2017 Session Slides and Samples Posted



I've posted my Session Slides and code samples from last week's DevIntersection conference on GitHub.

.NET Core 2.0 and ASP.NET Core 2.0 are Here



After a long wait .NET Core and ASP.NET Core 2.0 are finally here. This release is a major update from Version 1.0 that brings back a ton of functionality that was originally missing in .NET Core 1.x. With closer compatibility to full framework .NET it's much easier to port existing code to .NET Core, as having a much larger API surface to use in your applications. There are many usability improvements that make it easier to get started using considerable less fanfare. In this post I describe some of what's new and what's great and also a few things that are not so great.

A few notes on creating Class Libraries for ASP.NET Core



I recently started to collect some of my ASP.NET Core utilities into a helper support library as I tend to do. In the process I ran into a few snags and I realized I was making a few non-obvious mistakes right from the start. In this post I discuss a few of the issues with dependencies and how to deal with them.

Conditional TargetFrameworks for Multi-Targeted .NET SDK Projects on Cross-Platform Builds



If you build multi-targeted .NET SDK projects on multiple platforms you're going to find out that certain targets can't be build on certain platforms. If you target NetStandard and Net45 on a Mac, Net45 is going to fail. In order to get around this you need to conditionally build per platform. Here's how.

Accepting Raw Request Body Content in ASP.NET Core API Controllers



When posting raw body content to ASP.NET Core the process is not very self-explanatory. There's no easy way to simply retrieve raw data to a parameter in an API method, so a few extra steps are provided using either manual handling of the raw request stream, or by creating custom formatter that can handle common 'raw' content types in your APIs via standard Controller method parameters. In this post I look at various permutations and how you can access the raw data in your code.

Configuring LetsEncrypt for ASP.NET Core and IIS



LetsEncrypt makes it easy to create SSL certificates for your applications for free and lets you automate the process. When using LetsEncrypt with IIS and ASP.NET Core however a few extra steps are required to make an ASP.NET Core site work with LetsEncrypt. I show you how in this post.

Handling HTML5 Client Route Fallbacks in ASP.NET Core



HTML5 client routes work great on the client, but when deep linking into a site or pressing refresh in the browser, HTML5 client side routes have a nasty habit of turning into server HTTP requests. Requests to routes that the server is likely not configured for. In this post I look at why HTML5 client routes require server cooperation to handle and how to set them up on IIS and/or ASP.NET Core.

Multi-Targeting and Porting a .NET Library to .NET Core 2.0



I've been holding off porting any of my full frameworks to .NET Core. With the latest .NET Core 2.0 and .NET Standard 2.0 releases and their vastly larger footprints that match more closely with what we expect of the .NET Framework feature set, migrating looks a lot more appealing. In this post I describe the process of porting one of my general purpose full framework libraries to .NET Standard 2.0 and in the process also creating a multi-targeted project that compiles .NET 4.5, 4.0 and .NET Standard projects.

Upgrading to .NET Core 2.0 Preview



With the release of the first preview of .NET Core 2 and ASP.NET Core 2.0 I decided to upgrade my AlbumViewer sample application to the latest bits and preview tools. Overall the experience was pretty smooth, but I ran into a couple of breaking changes and a few tooling snags that I'll describe in this post.

IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing



If you're running ASP.NET Core under Windows with IIS, you'll want to take advantage of letting IIS serve up your static content and handle your HTML 5 Client and home routes. IIS is very efficient at handling static content and content re-routing and in this post I describe how you can properly configure ASP.NET Core applications using the AspNetCoreModule and IIS Rewrite Rules

Running .NET Core Apps under Windows Subsystem for Linux (Bash for Windows)



The Windows Shell for Linux (WSL or Bash on Ubuntu on Windows) provides a nice way for Windows and Linux to interact without the overhead of dealing with a separate VM. Using the WSL you can now also run your .NET Core applications directly under Linux without requiring a VM or Docker. In this post I demonstrate how the shell works and how you can run your .NET and ASP.NET Core applications to test operation under Linux.

Updating my AlbumViewer Sample to ASP.NET Core 1.1 and Angular 4



I updated my AlbumViewer sample application recently to the latest versions of ASP.NET Core (1.1) and the new .csproj project as well Angular 4

More on ASP.NET Core Running under IIS



Since my last post about hosting ASP.NET Core on IIS I've gotten quite a few questions and comments in regards to working with this mixed IIS/Kestrel hosting environment. There are quite a few not so obvious arrangement in this set up and some surprising discoveries in terms of performance and segragation of feature usage between IIS and Kestrel.

New CODE Magazine Article: Getting down to Business with ASP.NET Core



The latest issue of CODE magazine features my `Getting down to Business with ASP.NET` Core article as the cover article. The article focuses on building an ASP.NET Core backend for an Angular 2 front application, covering all aspects of separating business and Web app logic, dealing with EF Core data access in related tables, CORS to be able to run across domains and simple authentication in a client centric REST service application. Check it out.

.NET Standard 2.0 - Making Sense of .NET Again



It's taken awhile but it seems Microsoft is finally nailing the message for .NET going forward and .NET Standard with its common API specification is a huge part in making sure that the same base library of .NET is available on all .NET platforms. In this post I look at what .NET Standard is, how it works and what some of the surrounding issues and impacts are for the .NET Eco system.

Error Handling and ExceptionFilter Dependency Injection for ASP.NET Core APIs



Exception handling in API applications is important as errors - both handled and unhandled - need to be passed to clients in some way to let them display error information. ASP.NET's default error handling doesn't provide for object error results by default, but you can use an ExceptionFilter to intercept exceptions and format them yourself. In this post I look at how to create an API exception filter to create error object responses, and hook up custom logging of those errors to disk.

External Network Access to Kestrel and IIS Express in ASP.NET Core



Recently I needed to connect to my Windows based ASP.NET Core API from my Mac and in order for that to work some configuration settings are necesary so that the ASP.NET applications can serve HTTP content to the external network connection that this entails. In this post I show what you have to do to enable remote connections both using the Kestrel and IIS Express Web servers.

ASP.NET Core and CORS Gotchas



CORS is a requirement for cross domain XHR calls, and when you use Angular 2.0 default dev server and talk to an ASP.NET Core application you'll need to use CORS to get XHR to talk across the domain boundaries. Here's how to set up CORS and how to test it.

First Steps: Exploring .NET Core and ASP.NET Core



In this post I'll demonstrate how to get started with .NET Core and ASP.NET using the Command Line Tools. I'll create a few very simple projects and starting with a plain console application, show how to hook up ASP.NET, run an API and MVC app and then run the app locally on Windows and then move it over to run on the Mac. This is not meant to be your typical getting started tutorial that jumps right into Visual Studio and creating a Web project from there. Rather, the purpose of this post is to demonstrate some of the core underpinnings of how .NET Core and ASP.NET Core projects are bootstrapped to run.

Upgrading to ASP.NET Core RTM from RC2



I installed and upgraded an ASP.NET Core Sample application today and while the actual project upgrade process from RC2 was relatively easy, there were a few hiccups with installation and one of the breaking changes for the RTM release. In this post I'll go over some of the things I ran into and the workarounds.

ASP.NET Core and .NET Core Overview



ASP.NET Core and .NET Core are almost here, with the RTM release scheduled for the end of this month. In this post I’m going to revisit the high level overview architecture of .NET Core and ASP.NET Core since so much has changed, to help you understand how the pieces fit together and what it means to develop on the new stack along with some personal thoughts on how I plan to approach all of this new tech in my own work.

Publishing and Running ASP.NET Core Applications with IIS



If you plan on hosting ASP.NET Core applications on IIS, you'll find that the process to get your application to run is quite different than it was with classic ASP.NET. Because ASP.NET Core applications are essentially standalone Console applications that run outside of IIS, some special tooling and new publishing tools are required to get your apps up and running on Windows Server. In this post I'll give an overview of the architecture and show you how to deploy your ASP.NET Core applications using IIS on Windows Server.

Strongly Typed Configuration Settings in ASP.NET Core



ASP.NET Core provides built-in support for using strongly typed classes to represent configuration information. The configuration system provides a flexible mechanism for using different configuration storage providers and mapping those providers to your strongly typed objects. In this post I show how to set up strongly typed resources and use them in your ASP.NET Web applications.
West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2023