Quote of the Day

more Quotes

Categories

Get notified of new posts

Buy me coffee

All posts in "ASP.NET core"

Hosting a background task in an ASP.NET core application running on IIS.

Published May 22, 2019 in .NET core , ASP.NET core - 3 Comments

In this post, I share how I used the Microsoft.Extensions.Hosting.IHostedService interface and System.Thread.Timer class available in ASP.NET core to run a background job at a specified interval. It is straightforward for the most part, and Microsoft provides good documentation on the libraries. One thing that was not clear from the documents was handling overlapping invocations that happens when an invocation starts but the previous one has not finished within the specified interval. If you host your ASP.NET core on IIS, check out my other post to see how you can have your application and thus your background task auto start and run continuously on IIS.

Continue reading

Three ways of authenticating a Windows virtual machine against Azure Key Vault.

Published April 13, 2019 in .NET core , ASP.NET core , Azure , security - 2 Comments

In this post, I share three ways of gaining a Windows virtual machine access to a key vault. The machine can be an azure virtual machine or a non-azure machine such as your personal computer or a on premise server.

Continue reading

Deploy an ASP.NET core application to IIS on Windows Server 2019.

Published March 16, 2019 in ASP.NET core , Devops , IIS - 4 Comments

This is part II of the blog post series in which I share some of ways to build and deploy an ASP.NET core application to IIS running on a Windows VM. In the previous post, I cover how to build and published an ASP.NET core application. The end result is an artifact (a published directory). In this post, I go over how to deploy the artifact to IIS. Along the way, we’ll discuss:

  • Enabling IIS
  • .NET core runtime and hosting bundle
  • IIS website and application configuration
  • IIS application pool

Continue reading

Build and publish an ASP.NET core application using Visual Studio.

Published March 4, 2019 in ASP.NET core , Devops - 2 Comments

This is part I of the blog post series in which I share some of the ways I have learned to build and deploy an ASP.NET core 2 application to IIS running on Windows Server VM.

In this post, we’ll cover just the basics of how to build and publish an ASP.NET core 2 application to a folder using Visual Studio 2017. In the process, we’ll discuss some of the concepts you should be familiar with:

  • Release vs Debug build.
  • Deployment mode: framework dependent deployment vs self contained deployment.

I assume you have a working ASP.NET core application which you want to deploy. If not, you can just create a new ASP.NET core project, following the documentation.

Continue reading

How to auto start and keep an ASP.NET core web application running on IIS

Published October 7, 2018 in ASP.NET core , IIS - 26 Comments

I have an ASP.NET core web application which hosts a background task via the IHosedService interface. I wrote about it in this post, if you want more info. The task needs to run continuously to poll for messages on an azure queue storage every 5 seconds. I have learned the default settings on IIS do not start the application until it receives the first request. Additionally, if the application has not received a request after a predefined period of time, IIS kills the application.

I could have hosted the application as a Windows service or converted the application into a console application and use the Windows scheduler to have it run continuously. However, I find hosting on a real IIS server convenient and beneficial since we already have other applications running on IIS and we can access the application via HTTP.

In this post, I share how I make the application to auto start and always run on IIS.

If you have an ASP.NET or an ASP.NET core which hosts a background job that needs to always run, want to preload the application for performance instead of waiting for the initial request to hit the app, or just get some tips on IIS, then read on.

Continue reading

Secure app settings in ASP.NET Core 2

Published August 20, 2018 in ASP.NET core , security - 0 Comments

Update: This post shows how to authenticate to azure key vault using app id/secret. However, this approach is less secure than using managed identity for azure resource and certificate for non-azure resource to grant the resource access to the key vault. For production environment, you should definitely consider using azure managed identity or certificate to authenticate and access azure key vault from your resource. Checkout my other post for more details.

In this blog post, I’ll show you the steps on  how to keep the credentials out of the source code of an ASP.NET Core app using Azure Key Vault.

If you want some convincing examples why leaving secrets in the source code is bad, check out this post. 

I assume you have some familiarity with developing an ASP.NET core 2 app. You also need an Azure subscription to register your application in Azure Active Directory and create an Azure key vault.

Basically the process involves these steps:

  1. Register your application in AAD and generate app secret.
  2. Set application id/secret using environment variables.
  3. Create an Azure Key Vault.
  4. Grant your app access to your key vault using access control.
  5. Specify URL to your vault in app settings.
  6. Load app id and secret from environment variables.
  7. Read secrets from Azure Key Vault.

Checkout the sample app for this post from my Git repo.

Continue reading