1463 热度

由ASP.NET Core读取Response.Body引发的思考

前几天有群友在群里问如何在我之前的文章《ASP.NET Core WebApi返回结果统一包装实践》的时候有点疑问,主要的疑问点就是关于Respouse的读取的问题。在之前的文章《深入探究ASP.NET Core读取Request.Body的正确方式》曾分析过关于Request的读取问题,需要读取Response的场景同样经常遇到,比如读取输出信息或者包装一下输出结果等。无独有偶Response的读取同样存在类似的问题,本文我们便来分析一下如何进行Response的Body读取。使用方式我们在日常的使用中是如何读取流呢?很简单,直接使用StreamReader去读取,方式如下...

收录时间: 2023-04-11
分类: ASP.NET Core
贡献者: Rector
1322 热度

ASP.NET Core中如何限制响应发送速率(不是调用频率)

ASP.NET Core中有很多RateLimit组件,.NET 7甚至推出了官方版本。不过这些组件的主要目标是限制客户端访问服务的频率,在HTTP服务器崩溃前主动拒绝部分请求。如果请求没有被拒绝服务会尽可能调用资源尽快处理。现在有一个问题,有什么办法限制响应的发送速率吗?这在一些需要长时间传输流式数据的情况时很有用,避免少量请求耗尽网络带宽,尽可能同时服务更多请求。Tip本文节选自我的新书《C#与.NET6 开发从入门到实践》12.11 流量控制。实现方式偏向知识讲解和教学,不保证组件稳定性,不建议直接在产品中使用...

收录时间: 2023-03-12
分类: ASP.NET Core
贡献者: Rector
1794 热度

Multipart Form-Data in HttpClient with ASP.NET Core

In this article, we will learn what multipart requests are and how we can use them. Also, we will review examples of how to send data to remote servers using multipart form-data with HttpClient in ASP.NET Core.

收录时间: 2023-02-16
分类: ASP.NET Core
贡献者: Rector
1162 热度

Mocking dependencies in ASP.NET Core tests

As I recently spent some time writing and refactoring tests that utilize WebApplicationFactory, I’ve come to have some thoughts and ideas for improvement that I’d like to share. In this article, I’ll delve into the process of mocking dependencies in a DI container when using WebApplicationFactory, and offer some insights and best practices I’ve learned along the way. Whether you’re a seasoned pro or new to unit testing ASP.NET Core applications, I hope this information will be helpful as you work to simplify and streamline your tests.

收录时间: 2023-01-12
分类: ASP.NET Core
贡献者: Rector
1153 热度

How to Extract Custom Header in ASP.NET Core Web API

In this article, we are going to learn about the different ways we can extract Custom Headers from our ASP.NET Core Web API requests.

收录时间: 2022-12-08
分类: ASP.NET Core
贡献者: Rector
946 热度

Implement Feature Management in Blazor ASP.NET Core

The post shows how features toggles or feature switches can be implemented in an ASP.NET Core application using Blazor. The Microsoft.FeatureManagement Nuget package is used to add the feature toggles.

收录时间: 2022-12-08
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助
1107 热度

Exploring generating PDF files from HTML in ASP.NET Core

Back in 2008, I wrote a series of articles about using iTextSharp to generate PDF files in an ASP.NET application. I still use iTextSharp in a large MVC 5 application that I'm in the process of migrating to ASP.NET Core. The version I use is very old (4.1.6), and the API is very low level so it takes quite a while to write the code required to generate even a moderately complex PDF. Ideally I need a replacement for the new application that can generate PDF files purely from HTML, which is an API I'm much more comfortable with. This ancient version of iTextSharp doesn't support HTML as a source of content. In this article, I consider some alternatives.

收录时间: 2022-12-01
分类: ASP.NET Core
贡献者: Rector
808 热度

Contextual Feature Filters in ASP.NET Core

While custom feature filters solve the problem of isolating the feature to a specific group or individual it may not be appropriate to rely on the HttpContext for every application we build.

收录时间: 2022-11-09
分类: ASP.NET Core
贡献者: Rector
1327 热度

Performance Testing of ASP.NET Core APIs With k6

In this article, we are going to discuss how to do ASP.NET Core Performance Testing, specifically with the open-source tool k6. We’ll cover the need for performance testing, how to get the best results, and then dive into some examples of how k6 can help.

收录时间: 2022-10-12
分类: ASP.NET Core
贡献者: Rector
929 热度

ASP.NET Core 6: Bring your custom compression provider in gRPC

The compression of data during their transport on the Internet or a network makes it possible to gain significantly in terms of performance. If gRPC is already efficient thanks to the payloads transported in binary via HTTP/2, it is possible to improve its performance a little more. It is possible to use Gzip compression quite easily with gRPC, however if you plan to use another compression algorithm, such as Brotli, you will have to implement it yourself and that is what I will show you in this article.

收录时间: 2022-09-26
分类: ASP.NET Core
贡献者: Rector
1943 热度

Using Query String Parameters with Minimal APIs

In this article, we are going to explain how we can work with query string parameters in Minimal APIs in .NET 6. You may refer here for a nice introduction to the concept of Minimal APIs. Also, we will show new improvements that .NET 7 brings to the table.

收录时间: 2022-09-26
分类: ASP.NET Core
贡献者: Rector
1813 热度

Return File in ASP.NET Core Web API

In this article, we are going to learn how to return a file in an ASP.NET Core Web API and some concepts behind it. That said, we are going to implement a simple Web API to read a local file and return this file to download.

收录时间: 2022-09-14
分类: ASP.NET Core
贡献者: Rector
1357 热度

Feature Flags in ASP.NET Core

Being able to conditionally enable or disable features in our applications without redeploying our code is a powerful tool that we can take advantage of to quickly iterate on new features in our applications. In this article, we are going to learn about Feature Flags in ASP.NET Core, and how we can use them to turn features on or off dynamically.

收录时间: 2022-09-07
分类: ASP.NET Core
贡献者: Rector
1216 热度

ASP.NET Core on .NET 7.0 - Output caching

Finally, Microsoft added output caching to the ASP.NET Core 7.0 preview 6. Output caching is a middleware that caches the entire output of an endpoint instead of executing the endpoint every time it gets requested. This will make your endpoints a lot faster.

收录时间: 2022-07-27
分类: ASP.NET Core
贡献者: Rector
1191 热度

.NET WebAPI 使用 GroupName 对 Controller 分组呈现 Swagger UI

在日常开发 webapi 时,我们往往会集成 swagger doc 进行 api 的文档呈现,当api数量比较多的时候就会导致 swagger ui 上的 api 因为数量太多而显得杂乱,今天教大家如何利用 GroupName 属性来对 api 的 Controller 进行分组,然后利用 swagger ui 上的 Select a definition 切换功能进行多组 Controller 的切换。

收录时间: 2022-07-27
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助
1198 热度

What are Minimal APIs in ASP.NET Core 6

The goal of Minimal APIs in ASP.NET Core is to create HTTP API’s with minimum dependencies. In the world of microservices, the backend API’s are becoming way too smaller and easier to work with. The minimal API’s may come in handy when working with small API’s which has only a few dependencies.

收录时间: 2022-07-27
分类: ASP.NET Core
贡献者: Rector
1066 热度

ASP.NET Core updates in .NET 7 Preview 6

.NET 7 Preview 6 is now available and includes many great new improvements to ASP.NET Core.

收录时间: 2022-07-13
分类: ASP.NET Core
贡献者: Rector
1473 热度

Back to Basics: Custom HTTP Response Header Manipulation in ASP.NET Core

Custom HTTP Headers can be important in applications that need to explicitly manipulate headers either for system and security purposes, or for application specific messaging that provides app specific information to the caller which is not uncommon for API based implementations. For application headers, they are often used to communicate protocol or security information.

收录时间: 2022-07-11
分类: ASP.NET Core
贡献者: Rector
1505 热度

How to Resolve Instances With ASP.NET Core DI

In ASP.NET Core dependency injection, we usually register injectable dependencies at the start of our program. We can then resolve these dependencies (services) much later once when we need them. Sometimes, however, we may need to resolve those dependencies even before building our app. This happens especially when we need to initialize something at startup. This could range from a simple database for storage to a set of SCADA-controlled devices.

收录时间: 2022-07-06
分类: ASP.NET Core
贡献者: Rector
1614 热度

ApiController Attribute in ASP.NET Core Web API

In this article, we will learn about the ApiController attribute and the features it brings to our Web API controllers.

收录时间: 2022-06-27
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助