NET Core 拓展方法和中间件集合(支持NET Core2.0+)
# Pure.NETCoreExtentensions
https://github.com/purestackorg/Pure.NETCoreExtensions
NET Core 拓展方法和中间件集合(支持NET Core2.0+)
包含拓展方法:
DistributedCacheExtensions
ConfigurationExtensions
CookiesExtensions
ServiceCollectionExtensions
EnvironmentExtensions
HttpContextExtensions
HttpRequestExtentions
FormFileExtentions
HeaderDictionaryExtensions
DefaultIdentityUserClaimsExtensions
LoggerFactoryExtensions
UrlHelperExtensions
SmtpEmailSenderExtensions
WebHostBuilderExtensions
ApplicationBuilderExtensions
包含中间件:
FriendlyExceptionsMiddleware
HtmlMinificationMiddleware
HttpExceptionMiddleware
InternalServerErrorOnExceptionMiddleware
NoServerHttpHeaderMiddleware
ClientRateLimitMiddleware
IpRateLimitMiddleware
StatisticsMiddleware
常用基类:
BaseController
BaseControllerWithIdentity
TokenBucketLimitingService
LeakageBucketLimitingService
Platform
使用说明:
1.引用相关包:
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.2" />
2.引用命名空间
using Pure.NetCoreExtensions
3.配置 Startup.cs 文件
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
} app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=HelloWorld}/{action=Index}/{id?}");
}); //global middleware
app.UseGlobalHostingEnvironment(env)
.UseGlobalHttpContext()
.UseGlobalLoggerFactory()
.UseGlobalErrorHandling()
; app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
4.完成 !
下面测试代码和截图:
@{
ViewData["Title"] = "Index";
Layout = "_Layout";
}
@using Pure.NetCoreExtensions;
<h2>Hello World!</h2>
@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") <h3>Config</h3>
<p>
ConnectionString: @ConfigurationManager.Configuration.GetConnectionString()
</p>
<h3>AppSetting</h3>
<p>
<table>
<tr>
<td>Key1</td>
<td> @ConfigurationManager.AppSettings["Key1"]</td>
</tr>
<tr>
<td>Key2</td>
<td> @ConfigurationManager.AppSettings["Key2"]</td>
</tr>
<tr>
<td>Key2</td>
<td> @ConfigurationManager.AppSettings["Key3"]</td>
</tr>
</table> </p> <h3>Env</h3>
<p>
<table>
<tr>
<td>ApplicationName</td>
<td> @GlobalHostEnvironment.ApplicationName </td>
</tr>
<tr>
<td>ContentRootPath</td>
<td> @GlobalHostEnvironment.ContentRootPath </td>
</tr>
<tr>
<td>EnvironmentName</td>
<td> @GlobalHostEnvironment.EnvironmentName </td>
</tr>
<tr>
<td>WebRootPath</td>
<td> @GlobalHostEnvironment.WebRootPath </td>
</tr> </table> </p> <h3>Platform</h3>
<p>
<table>
<tr>
<td>OS</td>
<td> @Platform.OS </td>
</tr>
<tr>
<td>Is64BitOperatingSystem</td>
<td> @Platform.Is64BitOperatingSystem </td>
</tr>
<tr>
<td>OSDescription</td>
<td> @Platform.OSDescription </td>
</tr>
<tr>
<td>OSArchitecture</td>
<td> @Platform.OSArchitecture </td>
</tr>
<tr>
<td>ProcessArchitecture</td>
<td> @Platform.ProcessArchitecture </td>
</tr>
<tr>
<td>RuntimeType</td>
<td> @Platform.RuntimeType </td>
</tr> </table> </p> <h3>HttpContext</h3>
<p>
<table>
<tr>
<td>Current</td>
<td> @GlobalHttpContext.Current </td>
</tr>
<tr>
<td>Request.GetClientIpAddress </td>
<td> @GlobalHttpContext.Current.Request.GetClientIpAddress() </td>
</tr>
<tr>
<td>Request.IsLocalRequest </td>
<td> @GlobalHttpContext.Current.Request.IsLocalRequest() </td>
</tr>
<tr>
<td>Request.GetConnectionId </td>
<td> @GlobalHttpContext.Current.Request.GetConnectionId() </td>
</tr>
<tr>
<td>Request.ContentLength </td>
<td> @GlobalHttpContext.Current.Request.GetRequestId() </td>
</tr>
<tr>
<td>Request.GetUserAgent </td>
<td> @GlobalHttpContext.Current.Request.GetUserAgent() </td>
</tr> <tr>
<td>Response.ContentLength </td>
<td> @GlobalHttpContext.Current.Response.ContentLength </td>
</tr>
<tr>
<td>Response.ContentType </td>
<td> @GlobalHttpContext.Current.Response.ContentType </td>
</tr> <tr>
<td>Response.StatusCode </td>
<td> @GlobalHttpContext.Current.Response.StatusCode </td>
</tr>
</table> </p>
截图
NET Core 拓展方法和中间件集合(支持NET Core2.0+)的更多相关文章
- 开源且功能强大的C# 扩展方法类库Pure.Ext,包含1000+个拓展方法 (支持.Net Framework和.Net Core)
先上地址 Github: https://github.com/purestackorg/pure.ext Gitee: https://gitee.com/purestack/pure.ext 扩展 ...
- .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类
.NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...
- 反射 DataTable拓展方法 转实体对象、实体集合、JSON
Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...
- asp.net core中写入自定义中间件
首先要明确什么是中间件?微软官方解释:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?tabs=aspnet ...
- asp.net core mvc 管道之中间件
asp.net core mvc 管道之中间件 http请求处理管道通过注册中间件来实现各种功能,松耦合并且很灵活 此文简单介绍asp.net core mvc中间件的注册以及运行过程 通过理解中间件 ...
- ASP.NET CORE 管道模型及中间件使用解读
说到ASP.NET CORE 管道模型不得不先来看看之前的ASP.NET 的管道模型,两者差异很大,.NET CORE 3.1 后完全重新设计了框架的底层,.net core 3.1 的管道模型更加灵 ...
- asp.net core 3.1 自定义中间件实现jwt token认证
asp.net core 3.1 自定义中间件实现jwt token认证 话不多讲,也不知道咋讲!直接上代码 认证信息承载对象[user] /// <summary> /// 认证用户信息 ...
- 用UseMiddleware扩展方法注册中间件类
用UseMiddleware扩展方法注册中间件类 .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件 ...
- Zepto 添加手势判断拓展方法(思路+原理)
一.前言 这几个月事情比较多,写了一些博客都没有来得及整理发布,今天刚好有一位同事在开发前端页面的时候用到了手势判断.所以翻出了之前写的 demo,顺便整理一下作为记录. 手势判断在各种应用中都十分常 ...
随机推荐
- RabbitMQ 信道(channel)挂掉,但连接仍然存在,同时出现错误:Received remote Channel.Close (406): PRECONDITION_FAILED - unknown delivery tag x 的问题
该问题经过一番试验,发现是消费者(consumer)程序逻辑错误导致:在消息处理的回调函数中多次ack或nack. 开启Python日志,并在回调函数中两次ack得到如下信息: F:\software ...
- 372. Super Pow.txt
▶ 指数取模运算 ab % m ▶ 参考维基 https://en.wikipedia.org/wiki/Modular_exponentiation,给了几种计算方法:暴力计算法,保存中间结果法(分 ...
- 如何让自己的exe程序开机自启动
方法一. ①鼠标右键自己的exe程序,创建快捷方式 ②win+R,打开运行对话框,输入shell:startup,如下图: 将exe文件的的快捷方式拷贝到这个目录下,然后下次重启的时候自己的应用程序就 ...
- 【常见CPU架构对比】维基百科
Comparison of instruction set architectures https://en.wikipedia.org/wiki/Comparison_of_instruction_ ...
- k8s问题记录
1. kubectl run 起来的pod 用 kubectl delete po删不掉 kubectl delete deployment my-nginx kubelet# 看到最后一行:erro ...
- Spring AOP底层原理
------------------siwuxie095 Spring AOP 底层原理 AOP 即 Aspect Or ...
- 转)bash快捷键
粗体表示推荐,也许对每个人不同. Ctrl-A 相当于HOME键,用于将光标定位到本行最前面 Ctrl-E 相当于End键,即将光标移动到本行末尾 Ctrl-B 相当于左箭头键,用于将光标向左移动一格 ...
- git 常见报错
1. refusing to merge unrelated histories : 拒绝合并无关的历史 teminal中输入 git pull origin master --allow-unrel ...
- Linux grub命令
一.简介 GNU GRUB(GRand Unified Bootloader简称"GRUB")是一个来自GNU项目的多操作系统启动程序.GRUB是多启动规范的实现,它允许用户可以在 ...
- PHP逻辑运算符中的and和&&以及or和||是有区别的
下图是PHP的逻辑运算符: 看图中and和&&都是“与”,而or和||都是“或”,初开起来没有区别,但实际上这里面有一个优先级别的区别,即: &&和||的优先级别要高于 ...