30 热度

深入探究ASP.NET Core读取Request.Body的正确方式

相信大家在使用ASP.NET Core进行开发的时候,肯定会涉及到读取Request.Body的场景,毕竟我们大部分的POST请求都是将数据存放到Http的Body当中。因为笔者日常开发所使用的主要也是ASP.NET Core所以笔者也遇到这这种场景,关于本篇文章所套路的内容,来自于在开发过程中我遇到的关于Request.Body的读取问题。在之前的使用的时候,基本上都是借助搜索引擎搜索的答案,并没有太关注这个,发现自己理解的和正确的使用之间存在很大的误区。故有感而发,便写下此文,以作记录。学无止境,愿与君共勉。常用读取方式当我们要读取Request Body的时候,相信大家第一直...

收录时间: 2021-05-06
分类: ASP.NET Core
贡献者: Rector
26 热度

Using the ProblemDetails Class in ASP.NET Core Web API

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.

收录时间: 2021-05-06
分类: ASP.NET Core
贡献者: Rector
46 热度

Access Background Services From ASP.NET Core

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.

收录时间: 2021-04-30
分类: ASP.NET Core
贡献者: Rector
57 热度

Including linked files from outside the project directory in ASP.NET Core

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.

收录时间: 2021-04-27
分类: ASP.NET Core
贡献者: Rector
58 热度

Enable Razor Runtime Compilation

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.

收录时间: 2021-04-26
分类: ASP.NET Core
贡献者: Rector
57 热度

Specification Pattern in ASP.NET Core - Enhancing Generic Repository Pattern

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.

收录时间: 2021-04-26
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助
60 热度

ASP.NET CORE使用WebUploader对大文件分片上传,并通过ASP.NET CORE SignalR实时反馈后台处理进度给前端展示

本次,我们来实现一个单个大文件上传,并且把后台对上传文件的处理进度通过ASP.NET CORE SignalR反馈给前端展示,比如上传一个大的zip压缩包文件,后台进行解压缩,并且对压缩包中的文件进行md5校验,同时要求前台可以实时(实际情况看网络情况)展示后台对压缩包的处理进度(解压、校验文件)。在前端上传文件的组件选择上,采用了WebUploader(http://fex.baidu.com/webuploader/)这个优秀的前端组件,下面是来自它的官网介绍:WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件。...

收录时间: 2021-04-26
分类: ASP.NET Core
贡献者: Rector
34 热度

在Docker中运行ASP.NET Core MVC程序:使用docker-compose

在前面一篇文章中,演示了一个ASP.NET Core MVC应用程序,这个程序使用了MySQL,负载均衡,涉及到要创建多个容器,Volume卷以及自定义网络。这种纯手工的方式很容易出错,不仅每一个命令必须输入正确,并且每个步骤还要按照先后顺序来输入,比如再创建MySQL容器的时候,必须事先把其依赖的卷创建好。如果漏了某个步骤,或者某个步骤顺序发送错误,则程序就运行不起来。如果应用程序架构比较简单,这种问题不大,但当应用程序设计模块比较多时,可能会想到自己编写一些脚本来实现自动化,而Docker为我们提供了docker-compose功能,利用这以功能可以实现对复杂应用的管理,包括容器,Volume,自定义网络中。

收录时间: 2021-04-26
分类: ASP.NET Core
贡献者: Rector
56 热度

ASP.​NET Core in .NET 6 - Part 06 - Nullable Reference Type Annotations

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...

收录时间: 2021-04-23
分类: ASP.NET Core
贡献者: Rector
56 热度

ASP.NET Core 引用其他程序集项目里面的 Controller 控制器

我将控制器 Controller 按照不同的业务,分为多个不同的项目,我需要在路由里面调度到多个不同项目的控制器。只需要在 Startup 的 ConfigureServices 方法,调用 AddControllers 添加控制器,再加上额外的程序集即可,如下面代码,下面代码的 WeatherForecastController 是定义在另一个程序集的类...

收录时间: 2021-04-23
分类: ASP.NET Core
贡献者: Rector
44 热度

Securing multiple Auth0 APIs in ASP.NET Core using OAuth Bearer tokens

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.

收录时间: 2021-04-20
分类: ASP.NET Core
贡献者: Rector
60 热度

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.

收录时间: 2021-04-19
分类: ASP.NET Core
贡献者: Rector
50 热度

ASP.NET Core可视化日志组件使用

今天站长推荐一款日志可视化组件LogDashboard,可以不用安装第三方进程,只需要在项目中安装相应的Nuget包,添加数行代码,就可以实现拥有带Web页面的日志管理面板,十分nice哦。

收录时间: 2021-04-19
分类: ASP.NET Core
贡献者: Rector
73 热度

Generate Links To ASP.NET Core Map Endpoints

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.

收录时间: 2021-04-14
分类: ASP.NET Core
贡献者: Rector
74 热度

3 Easy Steps to Set Up Certificate Authentication in ASP.NET Core

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.

收录时间: 2021-04-14
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助
70 热度

Viewing overwritten configuration values in ASP.NET Core

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.

收录时间: 2021-04-14
分类: ASP.NET Core
贡献者: Rector
97 热度

使用SignalR ASP.NET Core来简单实现一个后台实时推送数据给Echarts展示图表的功能

什么是 SignalR ASP.NET CoreASP.NET Core SignalR 是一种开放源代码库,可简化将实时 web 功能添加到应用程序的功能。 实时 web 功能使服务器端代码可以立即将内容推送到客户端。SignalR ASP.NET Core可以做什么:需要从服务器进行高频率更新的应用。 示例包括游戏、社交网络、投票、拍卖、地图和 GPS 应用。仪表板和监视应用。 示例包括公司仪表板、即时销售更新或旅行警报。协作应用。 协作应用的示例包括白板应用和团队会议软件。需要通知的应用。 社交网络、电子邮件、聊天、游戏、旅行警报和很多其他应用都需使用通知...

收录时间: 2021-04-12
分类: ASP.NET Core
贡献者: Rector
97 热度

.NET 6 Preview 3 中 ASP.NET Core 的更新和改进

要在.NET 6 Preview 3 中开始使用 ASP.NET Core,请安装 .NET 6 SDK[1]。如果你在 Windows 上使用 Visual Studio,我们建议安装 Visual Studio 2019 16.10 的最新预览版。如果你在 macOS 上,我们建议安装 Visual Studio 2019 for Mac 8.10 的最新预览版。

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

Customizing Authorization Responses in .NET 5.0

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.

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

在ASP.NET Core中使用ViewComponent

在之前的开发过程中,我们对于应用或者说使用一些小的组件,通常使用分布页(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结尾。

收录时间: 2021-04-11
分类: ASP.NET Core
贡献者: Rector
AD 友情赞助