Edi Wang

.NET and Azure Developer

Posts in 2019

2019 年终回顾:不忘初心,负重前行

2019 年就要接近尾声,这一年对于我来说,有许多有意义的事件。我成长了许多,并依然保持着对技术的热情。在辞旧迎新之际,我想回顾一下我这一年中有意义的事件与收获,期待与大家一起在2020年继续成就不凡! 微软 MVP 全球峰会 今年3月,我有幸参加了在美国雷德蒙微软总部举办的MVP全球峰会,这是我第二次去美国,第一次去西雅图。我从小就崇拜比尔·盖茨先生及他创办的伟大的微软公司,而去微软总部参观,可以说是“朝圣”,我儿时的梦想之一终于实现,这次MVP全球峰会总算是拔了颗0x14年的草了。 (图:呼吸着微软总部的空气) 微软总部的园区非常大,需要乘坐 shuttle bus 穿梭于各个大楼之间。我们的会场在 Building 33,即 Microsoft Conference Center。4天的大会日程非常充实,可以了解到还未发布的新功能,也可以大量汲取其他MVP分享自己的技术精髓。 会 …
Azure Microsoft MVP

How to Allow Only Selected Users to Access an Application in Azure AD

My blog supports Azure AD authentication. I created the Azure AD application inside Visual Studio, by default, all users under my Azure AD will have access to my blog's admin portal. This is not ideal for an enterprise application that needs to limit access for only a few selected users or groups. Let's see how to configure an Application in Azure AD to enable access for just a few users. Make …
Azure Azure AD

Upgrade WinForms Apps from .NET Core 3.0 to 3.1

I upgraded a WinForms App to .NET Core 3.1 these days. It's an open-source on-screen ruler created by Jeff Key in 2004, the original code was for .NET Framework 2.0, I've already upgraded it to .NET Core 3.0 in September this year, it was very smooth without any code change. But this time, .NET Core 3.1 does require some code changes.  The project is on my GitHub: https://github.com/EdiWang/ …
.NET WinForm

Try the New Azure .NET SDK

Recently, Microsoft unveiled a new Azure .NET SDK, it's not a simple version upgrade, but a major change in the programming experience. While it may take a while to adapt to the new SDK, it is worth learning. The new SDK is more powerful, more flexible and easier to use. Current Status of Azure .NET SDKs Currently, the official packages for .NET SDKs for Azure are confusing and unfriendly to new …
.NET Azure SDK

A Brief Introduction for Azure Front Door

Microsoft Azure had an incident on 11/20, which its Front Door service got a bad deployment and blown-up Office 365, Bing, Azure DevOps, etc. Microsoft engineers very quickly fixed the issue. But Azure Front Door caught my eye, it is new to me. So I took a look. Azure Front Door Typically, when we deploy our web applications to Azure App Service or other clouds, the network flow of a …
Azure Front Door

Generate a True ICO Format Image in .NET Core

A while ago I finally completed the dynamic generation of favicons for my blog system. As we all know, favicon must have an icon in .ico format, and the rest can be output as png files and a manifest.json. However, this ICO format let me struggle for a while. I'd like to share my solution. The Problem with Built-in API As many of you may know, System.Drawing.Image has a Save method that allows …
.NET Icon

.NET成人礼 | 还记得20年前一起拖过的控件吗?

每一代人都有记忆里的味道。煤球炉、黑白电视机是属于父母的记忆。而“拖控件”式编程,启蒙了无数像我这样的80后(嗯,89也算80后)。 经典旧世 2000 年那个时候,上海这样的城市里也不是每家每户都有电脑,我家也没有电脑。我在学校经常听几位家里条件不错的同学说他们玩电脑的事情。CIH、千年虫等名词让我对电脑有着非常强烈的好奇心。而我第一次体验到计算机,是在我母亲单位的机房里。它是一台卧式机箱、15寸 CRT 凸面屏显示器的 Windows 95 电脑。 当时的微软对我来说就是神的存在。因为我认识电脑到使用电脑的一切几乎都离不开这家伟大的公司,它就像上帝一样开天辟地,创造了PC上的万物。Windows、Office、IE 这些当年几乎是唯一的主流产品。而微软的创始人之一比尔·盖茨也成了我的偶像。还记得当年,上海有个PC专题的电视频道,有一天该频道播放了比尔盖茨关于.NET战略的演讲,啥也不懂 …
.NET

Azure Remote Controlled Light with .NET Core 3.0 on Raspberry Pi

3 years ago, I wrote a blog post "Azure Remote Controlled Light with Windows 10 IoT Core", which is an experiment to sending a signal from your home and it will travel around the world then come back to your home to turn on an LED light on your Raspberry Pi. 3 years later, Windows 10 IoT Core and UWP seem not living so well. Microsoft doesn't have a new build of Windows 10 to support the latest …
.NET Azure Raspberry Pi Linux

This Blog Now Runs on .NET Core 3.0 and Azure

Microsoft shipped .NET Core 3.0 GA on Sep 23rd with tons of new features and improvements. This blog has been updated to .NET Core 3.0 and still runs on Microsoft Azure with SCD deployment type on App Service. This blog post summarizes all key points for my blog migration. Starting with .NET Core 3.0 preview 8, I've been investigating migration for this blog, from .NET Core 2.2 to .NET Core 3.0. …
.NET Azure

Migrate Azure Application Insights to ASP.NET Core 3.0

.NET Core 3.0 will be released at this month's .NET Conf conference, many of my friends, including me, couldn't wait to use the preview version to migrate our apps. Fortunately, starting with Preview 7, the API surface is final and can be treated as an RC version. There should be no API difference between preview 7, 8, 9 and RTM. Today I will talk about migration tips for Azure Application …
.NET Azure Application Insight

Setup Experimental Machines with Azure DevTest Lab

Programmers and test engineers always need to set up their own environments for development and testing purposes, and these machines may only be in use for a short period of time. Typically, we use virtual machine products such as Hyper-V and VMWare on the local machine, or we use virtual machines assigned by enterprise IT administrators to do the work. However, installing and managing these VMs …
Azure VM Lab Services

Deploy Ontology Blockchain DevTest Machine on Microsoft Azure

Learning blockchain development requires development and test environment. However, it is way too difficult for me to manually set up a dev-test machine because I am completely new to blockchain and it's development workloads. Fortunately, Microsoft Azure offers virtual machine images that allow vendors to publish pre-configured images to the Azure marketplace and distribute them across Azure. …
Azure Blockchain

Create Azure Function App with .NET Core and CD from GitHub

Azure Functions is an event-driven serverless compute platform that can also solve complex orchestration problems. Build and debug locally without additional setup, deploy and operate at scale in the cloud, and integrate services using triggers and bindings. For me, Function can help me quickly develop some simple APIs, and I just need to write business code instead of building fundamental code …
.NET Azure Azure Function GitHub

Create a Private DNS Server without VM on Microsoft Azure

In many companies and organizations, IT administrators typically configure internal private domain names that are inaccessible to the Internet for access to internal resources. For example, if my domain name is edi.wang, I want to use internal.edi.wang for access to the organization's internal resources. We have to install and configure our own DNS server on either Windows or Linux for this in …
Azure DNS

Run ASP.NET Core Websites with Windows Server Core on Azure

Microsoft Azure provides App Service that is fully managed to enable you to run websites. However, in some cases, you may still need an IaaS solution like a VM to host your website. This article will show you how to run an ASP.NET Core 2.2 web application on a Windows Server 2019 Datacenter Server Core virtual machine hosted in Azure. About Windows Server Core Windows was designed as an operating …
.NET Windows Azure

Run Office 97 on iPad with RDS on Microsoft Azure

Apple has been trying to make the iPad as a computer, but it's never as good as a real PC. If you can run PC software on an iPad, such as a full version of Office, that would be an ideal way. The first software I used when I was a kid was Microsoft Word in Office 97, which was the first version to introduce an Office Assistant (Clippy). In honor of Clippy that died at the age of seven, I decided …
Azure Office

About Per Monitor-DPI aware for WinForms Applications

WinForms is the traditional .NET desktop application workload running on Windows. For historical reasons, there are some problems with its support for high DPI and for different DPI screens, and this article explores the possible solutions. Windows "96" PPI history The default DPI for Windows systems (more precisely called PPI) is 96. PPI means pixel per inch, which means how many pixels are …
.NET WinForm DPI

How I Built This Blog with Azure Services

My website (https://edi.wang) is an open-source blog system written in .NET Core and runs on Microsoft Azure. This article explains why and how the blog benefits from Azure's services. History of this blog The history of my blog dates to 2003, and the .NET version of the blog was originally built 10 years ago by the ASP.NET 2.0 WebForm VB and Access database and has been gradually maintained and …
Azure DevOps App Service

Run Classic ASP on Windows 10 and Azure App Service

ASP is an old technology of Microsoft that even before .NET was born. I have used ASP 3.0 to create my first personal blog in 2003. Nowadays, it is hard to find ASP web applications still active on the internet. But we can still bring the 1996's classic ASP back to life on today's Windows 10 and even in Azure. Some history ASP and its successor, ASP.NET are completely different. ASP uses the …
ASP IIS Azure

Build a Simple Matrix Card in .NET

A Matrix Card is typically used in online games for authentication. I built a simple version of a Matrix Card in .NET Core today, let's check it out. How Matrix Card Works This is a typical Matrix Card for the game "World of Warcraft". It has a serial number to bind to the owner's game account, and then use the numbers in the table for validation. Suppose the hacker already knows your account …
.NET Matrix Card

Building a .NET Core URL Forward Service

I recently built a URL forward service named “Link Forwarder” using .NET Core 2.2. It’s open source and currently having a preview version deployed to my subdomain “go.edi.wang”. This article will share how I built it and what I learned. To help you understand the system and walk through the code, please check my GitHub repository for this project: https://github.com/EdiWang/LinkForwarder The …
.NET URL

IP Rate Limit for ASP.NET Core

In websites or API applications, we often want to block high-frequency requests in a short period of time for an IP to prevent boring people or malicious attacks. In ASP.NET Core, limiting the request rate of IP is now super easy, let's see. AspNetCoreRateLimit There's already a nice library for limiting request rate, called AspNetCoreRateLimit. GitHub: https://github.com/stefanprodan/ …
.NET ASP.NET IP

Reset Azure Blob Storage Content Type in .NET Core

My blog is using Azure Blob Storage to store images for posts, however, it went wrong these days when I am trying out Azure CDN, the cause is all my images requests are returning incorrect content-type. Let's see how to reset content type for files in Azure Blob Storage via .NET Core. When I uploaded images using the Azure Storage API for .NET, by default, without setting ContentType, which is …
.NET Azure Azure Blob Storage

SQL Server Export Data Tier Application via Command Line

We can use SSMS to export data-tier application for an SQL Server database. I've been using this method for several years on my local machine. However, to make things work under automated environments, like CI/CD environments, or some automated scheduled tasks. We usually need to do it under the command line.  Microsoft has provided a cross-platform command-line tool that can import/export DAC: …
SQL Server DAC

Stop Generating Designer.cs for .resx files in .NET Core

In Visual Studio, if we add a Resource File (.resx) to a .NET Core project, you will find a ".Designer.cs" file is automatically generated and updated whenever the resource content changes. This file basically contains auto-generated code for accessing resource values by key. In my blog system, I use the Resource File to maintain the default configuration data when setting up the blog for the …
.NET Visual Studio

How to Pack a .NET Core Class Library and Upload to NuGet

NuGet is the package manager of the. NET world, we can both use official website nuget.org, or build our own corporate and private servers. Now, with . NET Core, it's easier than ever to pack and upload a NuGet package, let's take a look! NuGet Account If you want your package to be used by every .NET developers in the world, then you need to have a nuget.org account to upload your own package.  …
.NET NuGet

Send Email in .NET Core via MailKit

The ability to send e-mail notifications is common in a variety of systems. My blog can also send emails to administrators when there are new comments, new replies, or when articles are referenced by other sites. So in. NET Core, how can we send an e-mail? My case will use Microsoft Outlook.com's personal account to send e-mail, using the SMTP protocol. But you can also do it with other SMTP- …
.NET Email MailKit SMTP

Use Environment Specific nlog.config in ASP.NET Core

ASP.NET Core has built-in aspsettings.env.json which can automatically apply to different environments. But how about NLog? In official examples, it only got one nlog.config file which will be used in all environments. Let's see how we can change it to use different config files on different environments. Why do we need this This requirement actually came from this blog system. My blog runs on …
.NET NLog

Operate Git with .NET Core

Git is the preferred source code version control tool for many programmers, and I've recently switched from TFVC to Git. I am going to show you how to operate Git with .NET Core. Why am I doing this First of all, we do have a lot of good Git clients, such as GitHub for Windows, VS/VS Code, git GUI, and so on, all quite mature, there is no need for us to reinvent this wheel in own. NET/C#. But on …
.NET Git

Restart an ASP.NET Core Application Programmatically

We developers won't have access to servers all the time, and without management capabilities, it will be difficut to restart a web application. However, in ASP.NET Core, there is a way for us to programmatically restart our application without requring management capabilities from server admins. IApplicationLifetime There is a IApplicationLifetime interface in ASP.NET Core which can handle events …
.NET ASP.NET

Read and Write Windows Registry in .NET Core

Yes, you read it right! It's totally possible! Even .NET Core is designed to be cross platform, but it does not mean you can not use platform specific APIs. Take Windows Registry for example, although .NET Standard can not contain Windows API like this. But there's still a way to use Windows Regisitry in .NET Core Applications. But first, you should be absolutely clear, that using platform …
.NET Windows Registry

Incremental Build Number for .NET Core via Azure DevOps

People familiar with the. NET framework knows that we can let the compiler self-increase the version number by specifying AssemblyVersion as 10.0.*. But. NET core and. NET Standard are not. Even with open-source projects like MSBump, there are certain flaws. Typically, such a requirement happens on a CI/CD server. Let's take a look at how to easily handle it with Azure DevOps. About Versioning in …
.NET PowerShell Azure DevOps

Send Email After Release Deployment in Azure DevOps

By default, Azure DevOps sends an email notification to team members after the compilation succeeds or fails. But in a CI/CD environment, we are more concerned about when the deployment is complete and then conducting manual or automated testing. Let's take a look at how to get Azure DevOps to automatically send mail notifications to team members after a successful deployment. Enter Project …
Azure DevOps

Fix .NET Core Website Failure After Deployment from Azure DevOps

I met a strange problem recently. After configuring the CI/CD pipeline with Azure DevOps and automatically deploy to Azure App Services, the. NET Core Website failed to start. Let's see how we can solve this problem. Find the issue First of all, fortunately, this is a staging environment. I found that the site unexpectedly did not log anything, even log directory cannot be found, which is very …
.NET Azure Azure DevOps

Fix Azure DevOps TF14045 Error When Deploy to Azure

I encountered an error when I tried to setup CI/CD in Azure DevOps, I tried to deploy a .NET Core application to Azure App Service, but Azure DevOps won't connect to Azure. This is a known issue for Microsoft. Let's see how we can manually set up a connection between Azure DevOps and Azure to work around this issue. First, the error message I met was: Failed to get resource ID for resource type ' …
Azure Azure DevOps Azure AD

Recommended Visual Studio Configuration for .NET Core Development

Visual Studio has always been a good friend to .NET developers, although VS Code can do .NET Core development, VS is still having a lot advantages. Let's see how to make Visual Studio more handy for .NET Core development. Basic Configuration First, please be advised, not all versions of Visual Studio supports .NET Core development, even some early version of VS2017. Some people may mistake for …
.NET Visual Studio

ASP.NET Core Dependency Injection in ActionFilterAttribute

In ASP.NET Core, we can easily use constructor injection to make Dependent Injections on components such as Controller and ViewComponent. But how to do it with ActionFilterAttribute? The Problem My blog system has an ActionFilter for deleting subscription files, and I want to log errors when an exception happens. I use NLog as the logging component, so I need to use LogManager. …
.NET Dependency Injection

Caveats in ASP.NET Core Data Protection

ASP.NET Core provides a built-in Data Protection mechanism to let us encrypt or decrypt sensitive data. There are some limitations that can cause problems while bringing convenience. I met some problems these days. My Scenario My blog system has a feature to send email notifications, so you need to configure an email account to let the program use that account to send mail to an administrator …
.NET AES Encryption

Auto Refresh Settings Changes in ASP.NET Core Runtime

In ASP.NET Core, if you modify the settings in appsettings.json, you will have to restart the site to take effect. Is there a way to refresh and apply it automatically after you modify the settings? Background Let's take a look at a website created by ASP.NET Core default templates. It includes two settings files: appsettings.json appsettings.Development.json The former one is used in production …
.NET ASP.NET