相信大家在使用ASP.NET Core进行开发的时候，肯定会涉及到读取Request.Body的场景，毕竟我们大部分的POST请求都是将数据存放到Http的Body当中。因为笔者日常开发所使用的主要也是ASP.NET Core所以笔者也遇到这这种场景，关于本篇文章所套路的内容，来自于在开发过程中我遇到的关于Request.Body的读取问题。在之前的使用的时候，基本上都是借助搜索引擎搜索的答案，并没有太关注这个，发现自己理解的和正确的使用之间存在很大的误区。故有感而发，便写下此文，以作记录。学无止境，愿与君共勉。常用读取方式当我们要读取Request Body的时候，相信大家第一直...
In this article, we are going to talk about the ProblemDetails class and how it plays a role in standardizing error and exception handling in our .NET Core APIs. To download the source code for this article, you can visit our ProblemDetails Class repository.
As a developer that’s seen most of the iterations of ASP.NET throughout their career, ASP.NET Core reduces the complexity of hosting a web application while giving developer’s the most power they’ve ever had. We can host ASP.NET Core applications within console applications, giving us some new and exciting scenarios. This post will show how to implement a BackgroundService within an ASP.NET Core application and communicate with our background service from an ASP.NET Core HTTP request.
This post is just a quick tip that I found myself using recently- including files in a project that are outside the project directory. I suspect this feature may have slipped under the radar for many people due to the slightly obscure UI hints you need to pick up on in Visual Studio.
Suppose you have been using ASP.NET MVC version 5.x for quite some time now and started to understand ASP.NET Core. In that case, I tell you you’re doing an excellent job because you’re upgrading your skills set to the latest version of ASP.NET Core. Have you ever wondered that we can enable runtime compilation of Razor files? Isn’t that exciting? I hope you’re excited because, in this tutorial, we’ll see how we can set up the runtime compilation.
In this article, we will talk about implementing Specification Pattern in ASP.NET Core applications and how it can enhance the already existing Generic Repository Patterns. We will be building from scratch, an ASP.NET Core WebAPI with Generic Repository Pattern, Entity Framework Core and finally implement the Specification Design Pattern. You can find the complete source code of this implementation here. Let’s get started.
本次，我们来实现一个单个大文件上传，并且把后台对上传文件的处理进度通过ASP.NET CORE SignalR反馈给前端展示，比如上传一个大的zip压缩包文件，后台进行解压缩，并且对压缩包中的文件进行md5校验，同时要求前台可以实时（实际情况看网络情况）展示后台对压缩包的处理进度（解压、校验文件）。在前端上传文件的组件选择上，采用了WebUploader(http://fex.baidu.com/webuploader/)这个优秀的前端组件，下面是来自它的官网介绍：WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主，FLASH为辅的现代文件上传组件。...
在前面一篇文章中，演示了一个ASP.NET Core MVC应用程序，这个程序使用了MySQL，负载均衡，涉及到要创建多个容器，Volume卷以及自定义网络。这种纯手工的方式很容易出错，不仅每一个命令必须输入正确，并且每个步骤还要按照先后顺序来输入，比如再创建MySQL容器的时候，必须事先把其依赖的卷创建好。如果漏了某个步骤，或者某个步骤顺序发送错误，则程序就运行不起来。如果应用程序架构比较简单，这种问题不大，但当应用程序设计模块比较多时，可能会想到自己编写一些脚本来实现自动化，而Docker为我们提供了docker-compose功能，利用这以功能可以实现对复杂应用的管理，包括容器，Volume，自定义网络中。
This is the sixth part of the ASP.NET Core on .NET 6 series. In this post, I want to have a quick into the new Nullable Reference Type Annotations in some ASP.NET Core APIs...
This article shows a strategy for security multiple APIs which have different authorization requirements but the tokens are issued by the same authority. Auth0 is used as the identity provider. A user API and a service API are implemented in the ASP.NET Core API project. The access token for the user API data is created using an Open ID Connect Code flow with PKCE authentication and the service API access token is created using the client credentials flow in the trusted backend of the Blazor application. It is important that both access tokens will only work for the intended API.
ASP.NET Core 5 & EntityFramework Core: Clean, clear and fluent integration tests with Calzolari.TestServer.EntityFramework, FluentAssertion.Web and xUnit
Not long ago I was asked to do integration tests with ASP.NET Core and Entity Framework Core and I was confronted with some difficulties, in particular the fact of testing Entity Framework Core in integration? I have not found a simple tutorial to create clear and simple tests and especially how to get around the limitations of Sql in memory when using EntityFramework Core. So I had to find work arounds with SqlLite to do my tests while making sure that there are no data collisions in each test. In addition, I wanted to make sure that I was using AAA (Arrange, Act, Assert) in such a way as to maintain optimal ideal readability. So I had the idea to create the Calzolari.TestServer.EntityFramework library which encapsulates all the management of EntityFramework Core in integration, this library also uses Flurl for writing Http clients in a fluid way and FakeBearerToken allowing to pass tokens in the simplest way in endpoints protected by JWTs. In this article I will also show how to use Calzolari.TestServer.EntityFramework in conjunction with FluentAssertions.Web which is an assertion library for the web and xUnit in order to perform really clean integration tests! I used as well AutoFixture to facilitate somme Arrange.
Routing is the backbone of every web application, and with ASP.NET Core, it’s never been easier to mix and match request handling frameworks. We can choose from MVC, Blazor, Razor Pages, SignlaR, Carter, and many more. Arguably the strength of ASP.NET Core is the interoperability of all of these approaches within a single host environment. In this post, we’ll see how we can name our Map methods so that we can generate links to the endpoints from anywhere within our ASP.NET Core application.
Ever wondered how to configure a simple yet secure authentication method in ASP.NET Core? Read on! This article aims to give you a minimum set of steps necessary to configure certificate-based authentication in ASP.NET Core. At the end of the article, I'll give you a list of more detailed resources, including a link to my test GitHub repo.
In a previous post I showed how you could create your own version of the IConfigurationRoot.GetDebugView() extension method, to visualize the configuration values in your ASP.NET Core app. In this post I continue on that path, adding additional functionality to the view—showing the overwritten values, as well as the final values.
什么是 SignalR ASP.NET CoreASP.NET Core SignalR 是一种开放源代码库，可简化将实时 web 功能添加到应用程序的功能。 实时 web 功能使服务器端代码可以立即将内容推送到客户端。SignalR ASP.NET Core可以做什么：需要从服务器进行高频率更新的应用。 示例包括游戏、社交网络、投票、拍卖、地图和 GPS 应用。仪表板和监视应用。 示例包括公司仪表板、即时销售更新或旅行警报。协作应用。 协作应用的示例包括白板应用和团队会议软件。需要通知的应用。 社交网络、电子邮件、聊天、游戏、旅行警报和很多其他应用都需使用通知...
One feature frequently requested in the ASP.NET Core Authorization Framework was the ability to customize the HTTP response when authorization fails. Previously the only way to this was to either invoke the authorization service (IAuthorizationService) directly in your controllers (or via a filter), similar to the approach for resource-based authorization or implement your own authorization filter.
在之前的开发过程中，我们对于应用或者说使用一些小的组件，通常使用分布页（partial view），再往前在Web Form中我们会进行应用WEB Control，好吧提及一个关键性代码TagPrefix：TagName，通过这种的标记我们便可以在我们web form中进行引入我们的组件，当然自从.NET MVC之后呢，就已经没有了WebControl，而对于.NET Core后，又多了一个特性ViewComponent。对于ViewComponent看起来它类似于小的控制器，而对于我们小的组件或者小部分通用型功能，可通过ViewComponent进行实现，比如说留言栏、菜单等等。ViewComponent是由两部分组成，一部分是类（通常该类集成与ViewComponent），而另外一部分是视图（Razor和普通的View一样），当然ViewComponent同样也支持POCO，不继承ViewComponent，但类名以ViewComponent结尾。