Microsoft FTE.

.NET Topics about .NET Core and C#


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 …

ASP.NET Core Reverse Proxy Web Proxy

Get unique random numbers in C#

The source code this blog mentioned is here: https://github.com/Anduin2017/SuperRandom The traditional methods for obtaining `n` non-repeating random numbers are: The random number is generated by the linear congruence method, and each random number is generated and compared in the database. If it already exists, the number is discarded. Randomly generate a linear sequence, and then …

C# .NET Core Algorithm Random Numbers Unique random Non-repeat Random


How to write a bot for Kahla

Kahla.SDK Kahla.SDK is a library for writting bots and extends for Kahla. Tutorial - How to create a bot with Kahla.SDK This will introduce how to write a bot for Kahla. Before starting, make sure you have .NET Core SDK installed. Download .NET Core SDK here. 1. Create a new console .NET Core app Open your terminal and type the following command to create a new console app. $ mkdir …

C# .NET Core Aiursoft Kahla Bot Kahla.SDK Kahla App Console App

Scan all accessible class in C#

Getting all accessible assemblies in C# is easy. Calling GetReferencedAssemblies and you can get all you referenced assemblies. But project reference is recursive. To get all the class, you need to build a reference tree and read from the entire tree. Consider the following code: private IEnumerable<Assembly> ScanAssemblies(Assembly entry) { yield return entry; …

C# .NET Core Reflection

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: …

ASP.NET Core C# class library View component

Inject an instance of a class with all default values

Last week while I was building a wiki generator and realized that I have to generate the possible responses of an API. Which means I need to get an object with all meaningful values in it. For example: { "value": { "id": "69c8981d-3498-48ff-8126-fcee0e8c8929", "conversationId": 0, "ats": [ { "targetUserId": "an example string." } ], "senderId": " …

C# .NET Core

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 …

ASP.NET Core .NET Core IP HTTP

How to run async method in C# synchronous method

In some situations, we may need to run an async method and get its result. But we can't access the await keyword. In the constructor method. When you are implementing an interface sync method. When you are implementing an abstract class sync method. I got a solution to unwrap the async method and call it in the synchronous method. First, put the following code anywhere you like: using …

C# .NET Core Async

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 …

ASP.NET Core C# .NET Core Entity Framework SQL Server

Upgrade existing class library to .NET Core 3.0

When we are upgrading our existing class library to the latest .NET Core, like this: <TargetFramework>netcoreapp3.0</TargetFramework> On doing so, you may get the following warning: C:\Program Files\dotnet\sdk\3.0.000\Sdks\Microsoft.NET.Sdk\targetsMicrosoft.NET.Sdk.DefaultItems.targets(149,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary …

C# class library .NET Core

  • 1