Edi Wang

.NET and Azure Developer

Posts in 2018

How to Remove Default FDS Effects in UWP Apps

The Fluent Design System introduced by Windows 10 from v1709 is very beautiful, the latest v1809 further refined FDS, many UWP built in controls got FDS effect by default while developers do not need to do anything. This is usually a good thing, but it can also cause performance problems for some apps. My Character Map UWP is one of the victimized apps, and let's take a look at how to remove the …
UWP

Dependency Injection with Multiple Implementations in ASP.NET Core

The built-in Dependency Injection (DI) in ASP.NET Core is very useful, but how do you deal with an interface has multiple implementations? Can the runtime choose one of these implementations based on configuration? Is there a way to get rid of reflection? Let me show you how to dynamically select a specific implementation of an interface at run time according to the configuration file without …
.NET ASP.NET Design Pattern Dependency Injection

Path Caveat with ASP.NET Core 2.2 IIS Hosting

ASP.NET Core 2.2 has been in place for some time, with a new feature that can use the new AspNetCoreModuleV2 and deploy with InProcess mode on IIS to dramatically improve performance. These days Azure App Service finally completed the deployment of this new version of the module, I configured my blog to the new module, and it exploded in production. Let's see why and how to solve it. If you don't …
.NET ASP.NET IIS

Automate Windows 10 Developer Machine Setup

One of the things programmers hate most is probably setup a computer. Because the programmer's computer environment configuration is very different from normal people. In general, it takes several hours to manually install a new development machine. Let this process automating, after all, the essence of programming is to let complex things simplify, find a way to be lazy! In fact, automatic …
Windows PowerShell Choco

Integrate Azure Application Insight Data into Your Own App

Microsoft Azure has a very powerful monitoring tool called Application Insights. It can monitor every aspect of our web application, including client and server metrics, error details, performance and so on. My blog is also using Application Insights, but everytime I want to see the data, I have to go to Azure portal, even for the basic metrics like page views or server response time. I want a …
Azure Application Insight

2018 "Hour of Code" in Sanda University with Microsoft MVPs

Nowadays, computer technology is breaking the limits of human beings every day, bringing countless innovations. Getting more teenagers to learn programming techniques will bring more wonderful surprises to our world. With this in mind, on December 8th, the "Hour of Code" event was held in Shanghai Sanda University campus, sponsored by Microsoft China Public Welfare group. Three Microsoft MVPs …
Microsoft MVP

Build .NET Core 2.2 Projects on Azure DevOps

.NET Core 2.2 has been release for couple of weeks. However, the build pipeline is still failing these days. Microsoft has not installed .NET Core 2.2 SDK to the hosted VS2017 agents yet. Let's see how to work around this issue and have a success build for our .NET Core 2.2 apps. 1. Add Task Edit your build definition, and click the "+" button to add a new task. 2. Add .NET Core SDK Installer …
.NET Azure DevOps

.NET Core WebUtility.UrlEncode or HttpUtility.UrlEncode

When we are dealing with URL encode in .NET Core 2.1, there are two APIs: System.Net.WebUtility.UrlEncode and System.Web.HttpUtility.UrlEncode. What's the difference between them? And which one should we prefer to use? I have done some research today, here's my findings. 1. Test Results First, let's see some tests. I've tested 2 couples of the same method between WebUtility class and HttpUtility …
.NET URL Encoding

Build a Pixel Ruler with UWP

In certain applications, we may need an on-screen ruler that indicates pixels on the screen. However, the only built-in ruler in UWP is within the InkToolbar control, we are not able to use it elsewhere. So, I will teach you how to build a pixel ruler which can be used anywhere in your UWP applications. The Demo App Create a new blank UWP application called PixelRulerUwp with minimal runtime …
UWP Win2D

Migrating Old ASP.NET Applications to .NET Core

More and more people are talking about .NET Core these days. It is true that .NET Core is the future, and .NET Framework will still be maintained because very large number of applications can’t be migrated in a short time. .NET Core and .NET Framework are just like electric cars and gasoline powered cars. Gasoline cars is mature, and you can drive it without any problem, but electric cars have …
.NET ASP.NET

Generate Captcha Code in ASP.NET Core

If you want to use captcha code to protect your website from spam messages, there are a few options such as Google ReCaptcha and captcha.com. Both of them can be integrated into ASP.NET Core applications. However, you may still want to generate the captcha code yourself for some reason, such as your website may be used in mainland China... This post will show you how to generate and use captcha …
.NET ASP.NET

Add Watermark to Uploaded Image in ASP.NET Core

Adding watermark to an image is very widely used in websites in order to protect the content owner's copyright, such as a blog system like this website. In traditional ASP.NET (.NET Framework), we could use System.Web.Helpers.WebImage to add text watermark like this: var image = new WebImage(imageBytes); image.AddTextWatermark( Settings.Instance.WatermarkText, "White", Settings.Instance. …
.NET ASP.NET

Fix AcrylicBrush Missing on NavigationView in Windows 10 SDK 17763

Microsoft released a new version of Windows 10 UWP SDK Build 17763, you can check the What's New document for more details. But when I retarget my App to version 17763, something unexpected happens, the AcrylicBrush gone missing if I change my App runtime to version 17763. I am not sure if this is by design on 17763 or it is a bug, I am trying to contact Microsoft product group on this problem. …
UWP

Get App Version in .NET Core

We can define versions on our .NET Core applications, but how to get the version at runtime? There are several ways to do it. First, let's see a typical .NET Core project file with versioning. We can define the version numbers for AssemblyVersion, FileVersion and Version in the project file (.csproj). The AssemblyVersion and FileVersion attributes must be in format of "major[.minor[.build[. …
.NET

Send AntiForgeryToken via jQuery Ajax in ASP.NET Core

In ASP.NET Core, if we use jQuery Ajax to post data to the server, and we want the ValidateAntiForgeryToken attribute to work. We have to do some tricks. The official document didn't document how to do it via jQuery. Let me show you how to do it. Please do read the official document first: https://docs.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-2.1  In my …
.NET AJAX ASP.NET jQuery

Prevent Image Hotlinking in ASP.NET/Core Applications

Introduction As a website developer, we sometimes don't want the images on our own website to be directly referenced and showed on other's website. It can cause a lot network bandwidth for our datacenters in some cases, which means costing money for us to pay for the one who use our images. For example, your website is A.com, you have an image on http://a.com/facepalm.jpg and B.com used your …
.NET ASP.NET IIS

How to Fix Extended TitleBar Overlapping NavigationView PaneToggleButton

In UWP Apps, we some times extend our main view into title bar to get rid of Windows 10 default title bar. However if you are using NavigationView under extended title bar, you will find your PaneToggleButton overlapped by the title bar. And the user won't be able to click on the upper part of the button because it is where the title bar need to respond to window drag actions. This image shows …
XAML UWP

Windows Community Toolkit: Use CameraPreview to Take Photos

In UWP Apps, if we want to use the device's camera to take photos and save to a file, it is used to be some how complicated, the developer need to know about quite a lot things and also write quite a few code to get it down (As you can find the Camera examples from Microsoft offical sample code). In fact, in many cases, we just want to take a photo by the most easy and default options via the …
UWP Camera

Read System Certificates in UWP

In Windows, we can view and manage the certificates using certmgr.msc, which is a system management console included in Windows itself.  However, what if we want to view the certificates information in an UWP app? Here is the answer. First thing first, the method I use does not apply to UWP only. In fact it is from a WPF app I wrote. As Microsoft released .NET Standard 2.0, which allows me to …
UWP

Send Feedback in UWP Apps by Windows 10 Feedback Hub

After our app has been put on Microsoft Store, there are a lot of ways to get users to send feedback, such as email, store reviews, or even write our own API collect feedback. But in fact, Windows 10 Feedback Hub can also be used to send feedbacks for our own Apps. Those who are familiar with Windows Insider know that when Windows 10 is installed, the system has a Feedback Hub, which is usually …
UWP

Customize Acrylic Brush in UWP Applications

Windows 10 Fall Creators Update (Build 16299) added acrylic brush, this is a UI brush that similar to Windows 7 Aero effect. A lot in box Windows Apps, such as Calculator are updated with the acrylic brush. However, the built in brushes will not always meet our own requirments. Especially when Windows automatically disable render of acrylic, such as low power mode, or with an inactive window, it …
UWP

Apply Keyboard Short Cuts in UWP

A greate Windows App requires not only mouse and touch screen friendly, but also need to think about keyboards. Especially for some common short cuts, like Undo (CTRL + Z). So that the App can provide better user experience.  So how can we define short cut keys in UWP? Take my App Tracing as example, I need to implement short cuts for Undo (CTRL + Z). First, we need to consider which Control is …
UWP