let today = new Beginning();

All Posts


Fire and forget in ASP.NET Core with dependency alive

C# fire and forget might not be suitable in ASP.NET Core To fire and forget in C#, it is really simple: Task.Run(() => FireAway()); But the same approach might not be suitable in ASP.NET Core Controller. Consider the following example: public class MyController : Controller { private readonly MyHeavyDependency _hd; public MyController(MyHeavyDependency hd) { _hd …

ASP.NET Core C# Async Fire and forget

How to serialize JSON object in C# without Newtonsoft Json

In many cases, we may not be able to access Newtonsoft.Json package. Like sometime there might be different packages using different versions of it, which may cause version conflict via build. That usually happens in some projects really large. So how can we play with JSON as while without it? In pure C#? First, copy the following class to your project: public static class MyJsonConverter { …

C# JSON .NET Newtonsoft.Json

Enable PowerShell remoting for Windows Server machines

Like you can use SSH to execute remote command on a remote Linux machine and you can also execute remote PowerShell on a target Windows Server. To enable it with a self-signed certificate, execute the following command: (Execute it on your server) > Get-ChildItem WSMan:\Localhost\listener | Remove-Item -Recurse # Remove old listeners > Cert = New-SelfSignedCertificate -CertstoreLocation …

PowerShell Windows Server Remote Management WMI

Best-practice for authentication after creating a new Linux server

This article helps you change the following items if your cloud provider didn't do that for you. Create your own account instead of root. Disable password login and force to use SSH key to log in. Disable root account. Enable sudo without password. Before starting the process, make sure you have a valid SSH key-pair locally. Fist, connect to the server. (With root password). you@local …

bash Linux Ubuntu SSH

Setup auto-renew wildcard HTTPS certificate on Azure virtual machine

Sometimes we might need to host a website in Azure. And there are so many options, like storage account, app service. But none of those supports wildcard HTTPS and auto-renew. An ideal configuration shall be static which means that it will never crash even when no one maintains it. Auto-renew is a must-have feature for HTTPS. Luckily, I got a solution based on win-acme: https://github.com/win- …

Azure Azure DNS Windows Server HTTPS Win-ACME Certificate letsencrypt ACME

C# Rotate the square matrix

This is one of my questions from an interview. The interviewer asked me to rotate a square matrix in C#. While it is not so hard for me and I have done it in 10 minutes, I'd share my solution to all developers who may need this. namespace Test { class Program { static void Main(string[] args) { var a = new int[][] { new int[] …

C# Algorithm Matrix Math

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

Fix Azure Media Player can't play video in iOS mobile devices

Recently, when we are trying to distribute video from Azure Media Service, we noticed that our video can't be played in iOS mobile devices. But the same web page plays normally in Android devices. There are multiple reasons for iOS devices to load and play Azure Media Player. As for the player itself is not open source, it might happen some strange effects when I change these settings. But the …

Azure Media Player Azure Azure Media Service

微信的架构是如何实现分布式消息分发?

我们每天的生活都离不开微信。微信基本上已经成了在中国生活的一部分。 但是,微信有些方面的功能总是看起来令人觉得有些奇怪。例如: 微信几乎是第一款需要手机扫码才能登录PC端的 微信群和微信聊天记录在切换设备后会完全无法同步 你无法得知自己是否被一个微信好友拉黑了 你不能同时在多个移动设备上同时登录微信 从产品的角度来看,这些设定看起来彷佛是在给用户制造障碍,也成了大家普遍对微信的槽点。那么,微信的团队为什么要这么设计,而为什么又不改良它的体验呢?我想或许问题并不只是产品和需求分析这么简单,而是还需要进一步探寻架构上的本质。 在我生活在澳大利亚期间,我发现一件很有趣的事情:在澳大利亚,我使用微信给同样在澳大利亚的好友发送微信消息,他也可以几乎瞬间收到。假想微信在国内建立单点的服务器,那么这种性能一定不足以支撑澳大利亚内的通信。数据从澳洲抵达中国再从中国推送到澳洲至少需要5 …

Web WeChat Distributed Messging IM

Download any Azure Media Service video or live stream with FFmpeg.

This blog shows a tutorial about how to download any Azure media service video or live stream. Before starting, you need to have FFmpeg installed. No matter you are using Windows, Linux, or Mac OS. Download latest FFmpeg here: https://ffmpeg.org/download.html After installing it, prepare a command: ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "{0}" -c copy video.mp4 And you …

Azure Media Player bash Azure Azure Media Service Download FFmpeg

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 …

ASP.NET Core C# SQL Server SQL Entity Framework Core Azure Redis Caching

在前端哈希密码是否是个不错的方案?

脑筋急转弯:为了防止运维人员能够直接去数据库里查看密码,Web应用普遍采用将密码哈希一趟后再存入数据库。需要校验时,由前端提供密码值,服务器将密码哈希后再比对,从而判断密码是否正确。这样运维人员即使接触的到数据库,也最多只能重置密码,无法登录一个特定的账号。那么,既然最终需要比对的是密码的哈希,为何不直接在前端哈希完,再直接把哈希后的结果发给服务器,来鉴定密码是否正确呢?答案其实挺简单的。当初我们加一次哈希是为了阻止运维登录。而如果哈希在前端完成,那么对于服务器而言,它其实只是做了一次明文的比较。数据库里的哈希值就相当于密码了。运维完全可以直接拿着哈希去调登录的API来获取一个账号的权限。 这个脑筋急转弯挺有趣的,乍一看仿佛还挺有道理的。但是换句话说,虽然看起来前端加哈希蠢蠢的,其实历史上有很多公司和项目都做过类似的事情。其中比较典型的就是腾讯公司的QQ了。 在十几年前的时候, …

Security Password Hash