Subscribe: Rick Strahl's Web Log
Added By: Feedage Forager Feedage Grade B rated
Language: English
code  configuration  content  core  iis  net core  net sdk  net  nuget package  package  projects  public  set public  set  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Rick Strahl's Web Log

Rick Strahl's Web Log

Life, Surf, Code and everything in between


Distributing Content and Showing a ReadMe file in a .NET Core Nuget Package

Tue, 30 Jan 2018 02:33:44 GMT

When you use NuGet with the new .NET SDK type project format, NuGet packages no longer can deploy content into the target project. In classic projects and full framework projects, you could add a content folder to your NuGet package and NuGet would install that content into projects root folder. There are good reasons why this change and removal happened: Bad package etiquette - polluting projects with extra files NuGet wouldn't remove content added through the package (since it can be changed) Keeping content updated and versioned along with the package is a pain Nevertheless, I have one package - Westwind.Globalization.Web - where having Content shipped as part of the package is very useful. West Wind Globalization's Web components include a Localization Administration UI and the UI's HTML, CSS and Script was previously shipped as Content in the old NuGet package. This still works for the full framework package: Figure 1 - Full framework packages still support Content folders that are expanded when installed When I recently ported this libary to ASP.NET Core - Westwind.Globalization.AspNetCore - I found out that I can no longer ship my Localization Admin UI via Content bundling inside of the NuGet package as the new .NET SDK projects that are required for .NET Core/Standard development no longer load the content. What used to work in Classic Projects NuGet packages for Full Framework projects can still package Content and Tools folders. Content and Tools Folders do not work in .NET SDK Projects Just keep in mind that the following sections apply only to full framework projects. There no longer is support for these in the new .NET SDK projects and while you can have the folders, they are ignored. Content The Content folder can hold arbitrary content that's dumped into the project's root folder. You can also use some limited templating to format some limited text expressions like project name, default namespace and class names inside of text documents. Tools Additionally you can also put a Powershell script into a Tools folder and Visual Studio will execute that install.ps1 script. The script has access to the Visual Studio IDE COM objects and with that you can bring up a Web browser window inside of Visual Studio to display more information, or open an external browser to show more information. In lieu of embedding content directly this is the next best alternative. The Newtonsoft.Json package does just this and you can actually Figure 2 - Newtonsoft.JSON is an example of a post-installer that displays a Web Page As you can see automating Visual Studio from Powershell is a sucky affair, but it works, although only for full framework. .NET SDK Projects - No more Content and Tools So in .NET Core/Standard projects which only support the new .NET SDK style project format, content or tools can no longer be distributed as part of NuGet package. Well, you can distribute it but they won't get installed. As you probably know by now, .NET SDK projects can optionally build a NuGet package as part of the project compilation process: Figure 3 - .NET SDK packages now allow you to generate a NuGet package for each target platform supported by the project. By default the package picks up the output binaries and xml doc files (and optionally pdb files) for library for each of the targets defined, which is an awesome feature if you've ever built multi-targeted projects with classic .csproj projects. For multi-targeted projects, the process of creating output and a NuGet package is drastically easier than the myriad of steps required in classic projects. Here's an example of a multi-targeted NuGet package of Westwind.Globalization which supports .NET 4.5+ and .NET Standard: Figure 4 - Multi-targeting in NuGet Packages from project build output is drop dead simple. But - no content. Externalizing the Content So for my ASP.NET core package Westwind.Globalization.AspNetCore package I no longer can distribute the LocalizationAdmin folder as part of the package. Instead I opted for putting the content into my GitHub repo and offe[...]

Code Magazine Article: Securing IIS Web Sites with Let’s Encrypt Certificates

Tue, 26 Dec 2017 20:33:53 GMT

I'm happy to point at my new CoDe Magazine article Securing IIS Web Sites with Let's Encrypt Certificates which is in the January/February edition issue:


I've written a few times about Let's Encrypt, which is an open source platform and protocol that provides free TLS certificates along with an API to facilitate automation of the certificate generation process. Additional tools provided by third parties then provide support features that make it drop dead simple to automatically create certificates and install them into Web Servers of choice.

This article summarizes the hows and whys of Lets Encrypt and provides a quick start on how you can use Lets Encrypt with standalone IIS servers. There really is no more excuse for even running that small hobby site that's public facing without IIS.

Go check it out and while you're at it check out the rest of this issue of CODE Magazine.

© Rick Strahl, West Wind Technologies, 2005-2018
Posted in Security  

Easy Configuration Binding in ASP.NET Core - revisited

Tue, 12 Dec 2017 09:10:30 GMT

A long while back I wrote a detailed and still relevant post that discusses ASP.NET Core's new configuration model and binding of configuration values to .NET types. In it I discussed the configuration system and specifically in how to set up configuration injection using IOptions. I really like the new model, which is much more flexible than the old, static ConfigurationManager in full framework because it provides strong typing on configuration settings out of the box. In the past I'd been using my own Westwind.Utilities.Configuration setup from Westwind.Utilities that provided much of the same functionality (interchangeable providers) - with .NET Core there's no need for a third (or for me first) party solution as the in-the-box implementation provides most of those same features. Nice. In the process of setting up a new application over the weekend I stumbled across an even simpler and - to me at least, cleaner - approach to configuring and injecting configuration into an application without using IOptions. Let's take a look. Create your Configuration Object ASP.NET Core's configuration system allows binding object properties to a series of providers. By default there's a JSON provider that looks at appsettings.json file, environment variables and the UserSecrets store. The config system can bind values from all these providers (and any others you might add) into a typed configuration object which can even include nested sub-objects. I'm working on updating my blog to .NET Core - it's time: The blog is 12+ years old and still running Webforms. For that app the beginnings of my configuration object looks like this: public class WeblogConfiguration { public string ApplicationName { get; set; } public string ApplicationBasePath { get; set; } = "/"; public int PostPageSize { get; set; } = 10000; public int HomePagePostCount { get; set; } = 30; public string PayPalEmail { get; set; } public EmailConfiguration Email { get; set; } = new EmailConfiguration(); } public class EmailConfiguration { public string MailServer { get; set; } public string MailServerUsername { get; set; } public string MailServerPassword { get; set; } public string SenderName { get; set; } public string SenderEmail { get; set; } public string AdminSenderEmail { get; set; } } Note that you can easily nest the configuration objects which helps organizing complex configuration settings into easily segregated blocks. Here I separate out the email settings into a separate nested class. I tend to use appsettings.json for most settings, and then use either user secrets for dev (so the values don't get shared to source control) or environment variables in production to feed in the sensitive values like passwords. Here's the relevant appsettings.json that has all the fields from my configuration mapped to a Weblog property key: { "Logging": { ... } }, "Weblog": { "ApplicationName": "Rick Strahl's WebLog (local)" "ApplicationBasePath": "/", "ConnectionString": "server=.;database=WeblogCore;integrated security=true;MultipleActiveResultSets=True", "PostPageSize": 7600, "HomePagePostCount": 25, "Email": { "MailServer": "", "MailServerUsername": "", "MailServerPassword": "nicetry", "SenderEmail": "", "SenderName": "West Wind Weblog", "AdminSenderEmail": "admin Administration" } } } Setting up Injection in Startup.cs To start, we need an IConfiguration instance which is the configuration root object. As of .NET Core 2.0 IConfiguration is a default service that can get injected automatically - it's one of the pre-configured services registered with the DI system as part of the .NET Core bootstrap[...]

Working around the lack of dynamic DbProviderFactory loading in .NET Core

Tue, 28 Nov 2017 01:19:34 GMT

.NET Core and .NET Standard are missing the DbProviderFactories class which is used to dynamically load ADO.NET DbProviderFactory instances which in turn are used to gain access to the various ADO.NET intrinsic objects generically without requiring an explicit reference to the data access provider. In this post I describe why this can be a problem for libraries that use multiple data providers and show a workaround for loading a DbProviderFactory without taking an explict dependency on the provider assembly.

Using Gists for General Purpose Web Pages with Markdown

Mon, 20 Nov 2017 17:59:22 GMT

Most of you probably know and use Github Gists for sharing Code snippets. But did you know that Gists also support Markdown? Using Markdown makes it easy to create much richer code shareable code and even allows for an easy way to create self-contained Web content.

Flexing your HTML Layout Muscles with Flexbox

Sun, 12 Nov 2017 07:10:00 GMT

Flexbox is a CSS based technology that makes it much easier to create structured layouts with HTML and CSS. Based on a containership hierarchy, Flexbox combines the structured features of tables with the free form layout capabilities of arbitrary HTML elements that make it possible to create complex , yet flexible HTML designs much more easily that was otherwise possible. My article in CoDe Magazine describes the reasons for Flexbox, the basics of operation and few practical examples you can use today to put flexbox to use.

Dev Intersection 2017 Session Slides and Samples Posted

Thu, 09 Nov 2017 07:31:20 GMT

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

Mon, 23 Oct 2017 06:19:51 GMT

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.

Opening a Web Browser with an HTTP Url from Visual Studio Code

Fri, 13 Oct 2017 21:28:20 GMT

Here's a quick tip on how you can create a project specific Visual Studio Task that can launch a Web Browser to a specific page quickly and easily.

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

Tue, 26 Sep 2017 16:09:13 GMT

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.

WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

Mon, 25 Sep 2017 17:54:30 GMT

I ran into a nasty problem with spell checking on WPF, which caused any form that uses spell checking to load extremely slow. It turns out the problem was caused by errant entries in the global Windows dictionary key in the registry. This post describes the problem and how to find and fix your global Windows dictionary settings.

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

Mon, 18 Sep 2017 18:07:57 GMT

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

Thu, 14 Sep 2017 18:39:53 GMT

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.

A Literal Markdown Control for ASP.NET WebForms

Wed, 13 Sep 2017 17:00:50 GMT

Spent some time last night creating a small ASP.NET Server control that can render literal Markdown text inside of ASPX pages and turn the literal text into Markdown. It's a very simple control, but it makes it lot easier to edit documents that contain simple formatted text content without having to deal with angle brackets for lengthier text.

Configuring LetsEncrypt for ASP.NET Core and IIS

Sat, 09 Sep 2017 17:12:01 GMT

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

Mon, 07 Aug 2017 17:40:07 GMT

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.

Updating Windows Applications and Installers for non-Admin Installation

Tue, 18 Jul 2017 06:54:04 GMT

I recently updated Markdown Monster to run as a non-admin installation even when running the full installer. There have been many requests for this functionality and in this post I describe several of the updates required in order to make this work.

JavaScript Debugging in a Web Browser Control with Visual Studio

Fri, 07 Jul 2017 02:24:15 GMT

Debugging a Web Browser Control embedded in a Windows application can be a bear because there's no obvious way to debug the the JavaScript code or HTML DOM/CSS inside of the application. Although the Web Browser uses the Internet Explorer Engine for HTML rendering and JavaScript execution and provides most of the engine features, the Debugger and F12 are not part of that. As it turns out you can use Visual Studio to hook up a script debugger and provide a rich debugging experience with the full IE debugger, Console and even a DOM/CSS Explorer. In this post I show how.

Debouncing and Throttling Dispatcher Events

Mon, 03 Jul 2017 05:32:49 GMT

In UI applications it's not uncommon for a number of UI events to fire more events than your application can handle. In order to limit the number of events it's often a good idea to throttle or 'debounce' events so that only a single event is fire for a given period. In this post I describe a Dispatcher based implementation for debouncing and throttling UI events in WPF applications.

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

Thu, 22 Jun 2017 16:46:07 GMT

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.

Bypassing IIS Error Messages in ASP.NET

Thu, 01 Jun 2017 22:30:42 GMT

IIS Error handling is the source of lots of confusion. I've been using IIS for nearly 20 years now, and figuring out the right combination of error configuration settings and code to properly serve custom error pages or error responses in API still makes fumble a few times before I get it just right. This post provides a few hints and some background on how to deal with error handling.

Automating IIS Feature Installation with Powershell

Thu, 25 May 2017 19:30:28 GMT

IIS often gets a bad wrap for being diffcult to install and configure. However, using some of the built-in tooling for administration using PowerShell it's actually quite easy to configure IIS and even set up a new site and application pool with a few short scripts that are much quicker, and more repeatable than using the various Windows UI features. Here's how.

Upgrading to .NET Core 2.0 Preview

Tue, 16 May 2017 04:42:00 GMT

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

Fri, 28 Apr 2017 02:26:44 GMT

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

Creating a Markdown Monster Addin: Save Images to Azure Blob Storage

Mon, 17 Apr 2017 16:30:29 GMT

The Markdown Monster Markdown Editor and Weblog Publishing tool has a .NET based addin model that makes it relatively easy to extend its core feature set with custom functionality. In this post I show how you can quickly create an addin of your own, and then show a practical example that demonstrates how add Image uploading to Azure Blob storage as an interactive addin.