Posts about ASP.NET Core

JWT authentication for gRPC

July 12th 2024 OAuth ASP.NET Core

In a recent blog post, I described how to add JWT authentication to an ASP.NET Core Web API project. This time I'm doing the same for a gRPC project. To test the authentication, I'm using similar Web API integration tests, with slightly modified setup to make them work with gRPC.

Auto-redirect in REST client tools

While preparing the sample project for my blog post about JWT authentication, I spent too much time troubleshooting an issue with failed authentication of calls from .http files in Visual Studio. It turned out to be caused by how Visual Studio handles redirects. I decided to check how Bruno and Postman behave in this scenario.

JWT authentication for Web API

June 28th 2024 OAuth ASP.NET Core

Although there's great support for JWT bearer authentication in ASP.NET Core, I had a hard time finding clear instructions on how to add it to an existing ASP.NET Core (Web API) project. In the end I decided to create my own sample project as the basis for discussing the ins and outs of JWT authentication.

Web API integration tests

I wrote a post about integration testing web APIs a while back. But when I wanted to use the same approach in a project with top-level statements, it wasn't immediately obvious to me how. While looking for a solution, I stumbled across some documentation for an even simpler approach.

Hide endpoints for disabled features in OpenAPI

June 7th 2024 OpenAPI ASP.NET Core

The .NET Feature Management libraries are great for toggling the availability of ASP.NET Web API endpoints with feature flags. Unfortunately, such endpoints will still show up in the generated OpenAPI specification even when the feature flag is disabled. To hide them, you need to implement a custom filter for Swashbuckle.

OpenAPI docs for models from another assembly

March 29th 2024 OpenAPI ASP.NET Core .NET

By default, the OpenAPI specification created by Swashbuckle for ASP.NET Core web API doesn't include the descriptions for endpoints and models from XML comments. There are step-by-step instructions how to add them in the documentation, but even then there will be no descriptions for models from other assemblies.

GitHub Actions and multi-project solutions

August 26th 2022 GitHub ASP.NET Core Azure

GitHub Actions can be a good choice for deploying an ASP.NET Core application to an Azure Web App Service if you have the code in a GitHub repository. You can even generate the GitHub Actions workflow directly from the Azure Portal. However, if your solution is not very simple, the generated workflow may not work correctly.

Unit testing ASP.NET Core Web API

August 5th 2022 ASP.NET Core Unit Testing

In a previous blog post, I looked at integration testing of ASP.NET Core Web APIs. But often unit tests make more sense. So instead of checking the already serialized responses from the REST service, you would check the value returned by the controller action method before it is serialized into an HTTP response by the ASP.NET Core runtime.

ASP.NET Core nullable route params in Swagger

July 22nd 2022 OpenAPI ASP.NET Core

I recently had an issue with optional route parameters in ASP.NET Core Web API not showing as such in the Open API specification generated by Swashbuckle. The most comprehensive source of information I could find on this issue was a blog post, which I used as a basis for further research.

Truncated JSON response from web API

November 5th 2021 ASP.NET Core Serialization

An endpoint in my ASP.NET Core web API project suddenly started returning a truncated JSON response with a 200 response code. According to the logs, an exception was thrown, but for some reason the response code was not 500 as I would expect.

Web API testing in ASP.NET Core

ASP.NET Core provides great support for integration testing of Web APIs. You can host the server in the test process and still make requests over HTTP. However, if your app reads its configuration from the appsetting.json file, you'll quickly find that the test server cannot find your regular configuration file.

Custom Data in Braintree Hosted Fields

March 3rd 2017 Braintree ASP.NET Core

Braintree's Hosted Fields offering is a great compromise between payment form customization and PCI SAQ A compliance requirements. Although it is not immediately evident from the documentation, the payment form can also easily be extended with custom data fields that your business might require. This post demonstrates how to do it in an ASP.NET Core application.

Deploying ASP.NET Core RC1 Application to IIS

February 14th 2016 ASP.NET Core IIS Visual Studio

If you're used to the old ASP.NET, it's not all that obvious how to deploy an ASP.NET Core application to IIS. Although, there is documentation available for the process, I still struggled a bit, before I got everything working. This post contains the steps I had to take, so that I can simply follow them the next time. At least, until something changes again with one of the future releases.