ASP.NET Core


Creating a proxy to another URL with ASP.NET Core

This post talks about writing a simple HTTP proxy logic in C# or ASP.NET Core. And allowing your project to proxy the request to any other URL. It is not about deploying a proxy server for your ASP.NET Core project. Before starting, you need to be clear about the target you are going to proxy for. It shall be an URL. Add the following code anywhere of your project. public static …


EF second layer cache to enhance your SQL database performance based on Redis

Entity-Framework Core is a lightweight, extensible, open-source, and cross-platform version of the popular Entity Framework data access technology. It really helps the developer to build applications which access database easily. But in most cases, we may cache some results which do not change frequently, to reduce access to our database. For example, the home page of a blog may not change …


HTTP post file from .NET Core new HTTP client

Now with .NET Core 3, Microsoft released a new .NET Core HTTP client. Reference: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1 With the new client, to call a WEB API is much easier. For example, to make an HTTP GET request: var request = new HttpRequestMessage(HttpMethod.Get, url) { Content = new …


Microsoft account integrated sign in via C#

This code example indicates how to build an app that supports Microsoft account OAuth authentication. Before coding, we gonna create an app in your Azure portal first. https://portal.azure.com The name is your app's display name. Select your app can access accounts in any organization and personal Microsoft account. As for the redirect URI, it must be your server redirect back address. For …


Share view component between different ASP.NET Core web project

When some logic in C# can be shared between projects, we gonna create a new class library project. But sometimes we just want to share some view components. For example, for all pages in Aiursoft, it all contains a Logout component. Writing this more than one time doesn't make sense. So how can we share it? First, we gonna create a new .NET Core class library project alongside it. Name it: …


Support multi-tenant in pure Entity Framework Core

Multi-tenant requires many features because the data can be separated by different tenants. So when you are accessing the database, you don't need to worry that your operation will affect other tenants. Multi-tenancy is the ASP.NET boilerplate's most important feature and works perfectly with Domain-driven design. But how can we implement the multitenant feature with only pure Entity Framework …


Auto update database for ASP.NET Core with Entity Framework

If your ASP.NET Core project is connecting to your database via entity framework, you can't be unfamiliar with the script: dotnet ef database update. Without executing the script your database is not the latest and this may cause some issues. Traditionally we update the database every time we start our app or publish our app. But we may forget this process and it costs us work. How can we …


Limit ASP.NET Core request frequency by IP address

By default, the user can request an ASP.NET Core web server unlimitedly. The user may request our web server very frequently and submit lots of spam data. Also, too frequent requests may be a terrible attack which may cost our service down and lots of money. So how can we group the requests by their IP address, limit the frequency of the user requests, and return an error message? There's …


Consolidate all Entity-Framework database migrations to one migration

Why do we need to do that? In case you ruined your code or you have too many migrations and caused your editor slow, you may want to reset all migrations. However, deleting all migrations directly in your code will cause database update fail. So I will talk about my solution about how to consolidate all migrations without deleting any data. The following steps only suitable for code-first EF …


Using IIS and web.config to support large file upload

When you try and upload a large file (over the size limit in IIS) you will see an error message that looks something like: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. By default, IIS web server allows for limited file size to be uploaded to the web …