Edi Wang

.NET and Azure Developer

All Posts

Upload File with Progress from Browser to Azure Blob Storage

I am currently developing an internal OA system for a small company. One of the business requirements is for users to upload attachments when creating a ticket. Azure Blob Storage is an ideal solution for this scenario. However, since the attachment sizes range from a few kilobytes to several hundred megabytes, it is crucial to display a progress bar during file uploads. Let's explore how we can easily implement this using Azure.
Azure Azure Blob Storage

Identify Users from Different Countries and Regions for Websites on Azure

For websites that need to display different content for users in different countries and regions, we usually identify the user's location based on the IP address. It means we have to write our own code, purchasing and maintaining an IP database, or using a third-party IP data service, it will take huge efforts. How to quickly do it without purchasing an IP database and write a lot of code? …
Azure Front Door

Hosting Static HTML Website with Azure Static Web Apps

When I choose free static website hosting plans, I would use GitHub pages in the past. But now, since the GA of Azure Static Web Apps (SWA), I now have another free of charge option. I've tried to host a few pure HTML/JS website as well as .NET Blazor WASM applications with Azure Static Web Apps. In this post, I'll share how to create a static website by SWA. …
Azure

ASP.NET Core Unit Test: How to Mock HttpClient.GetStringAsync()

In ASP.NET Core unit tests, if you want to mock HttpClient.GetStringAsync(), here's the trick. Problem Given the following code var html = await _httpClient.GetStringAsync(sourceUrl); When I tried to mock HttpClient.GetStringAsync() like this var httpClientMock = new Mock<HttpClient>(); httpClientMock .Setup(p => p.GetStringAsync(It.IsAny<string>())) .Returns(Task.FromResult("...")); Moq …
ASP.NET Unit Test

How to Prevent Access to App Service Url Behind Azure Front Door

In my previous posts, I have introduced usage of Azure Front Door. However, when we finish setting up the front door and bind our domain to the front door, users can still access the App Service URL. In this post, I'll introduce how to prevent access to our App Service when using Azure Front Door. Problem For example, my blog is binding https://edi.wang to my front door, I have 2 App Services …
Azure App Service Front Door

ASP.NET Core Unit Test: How to Mock HttpContext.Features.Get()

In ASP.NET Core unit tests, if you want to mock HttpContext.Features.Get<SomeType>(), here's the trick. Problem I have my Error page code that will get exception detail infomation, to do that, I use HttpContext.Features.Get<IExceptionHandlerPathFeature>(). public void OnGet() { var requestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; var exceptionFeature = HttpContext.Features. …
ASP.NET Unit Test

ASP.NET Core Unit Test: How to Mock Url.Page()

Problem In ASP.NET Core, when you use extension methods on UrlHelperExtensions class, it would be difficult to write Mock in unit test. Because Moq doesn't support mocking extension methods. For example, the following code that I use in my blog is using Url.Page() method: var callbackUrl = Url.Page("/Index", null, null, Request.Scheme); But in my unit test, mocking like this will throw …
ASP.NET Unit Test

RMB capitalization converter in Blazor WASM

.NET 5 正式发布已经有一段时间了,其中 Blazor 技术是该版本的亮点之一。作为微软技术的被坑者,年少的我曾经以为 SilverLight 能血虐 Flash,Zune 能团灭 iPod,WP 能吊打 iPhone,UWP 能统一全平台…… 可是后…… 最终步入大龄程序员的我发现,只有陪伴了我将近 20 年的 ASP.NET 还没有完蛋。于是我这两天花了点时间,尝试将我的一个 UWP 小工具用 Blazor 重写,分享给大家。 无法抢救的 UWP “人民币大写转换器” 是我年少无知时开发的小工具之一,它的主要功能有: - 将数字金额转化为大写中文 - 复制结果 - 使用中文语音朗读结果 - 显示参照表 可惜 UWP 不论是充满 Bug 的 SDK,Runtime,还是微软的龟速更新与混乱的规划,都已经无可救药了,是时候给应用找个新家了。 Blazor Blazor 是 .NET
.NET Blazor WASM

ASP.NET Core 5.0 Throughput Test in Kestrel, IIS, Nginx and Caddy

Starting from version 2.2, ASP.NET Core allow you to use the InProcess mode to improve performance under IIS. Rick Strahl has a detailed article on this. Three years have passed, and now ASP.NET Core has reached version 5.0, how the performance diffs between servers? Let's take a look together. Rick's Test Result In the original article, Rick Strahl tested the performance of ASP.NET Core 2.2 in …
ASP.NET IIS Linux

Setup Cat Live Streaming on Microsoft Azure

Cats are very helpful for programming. But when we are not at home, how can we remotely watch the cat and let our friends watch it together? With Azure, this problem will be solved! Live broadcast equipment and software USB Camera In terms of hardware, we only need an ordinary USB camera. It is recommended to use a camera with auto focus and resolution above 1080p. The image sensor of the camera …
Azure Azure Media Service