# 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+)的更多相关文章

  1. 开源且功能强大的C# 扩展方法类库Pure.Ext,包含1000+个拓展方法 (支持.Net Framework和.Net Core)

    先上地址 Github: https://github.com/purestackorg/pure.ext Gitee: https://gitee.com/purestack/pure.ext 扩展 ...

  2. .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类

    .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...

  3. 反射 DataTable拓展方法 转实体对象、实体集合、JSON

    Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...

  4. asp.net core中写入自定义中间件

    首先要明确什么是中间件?微软官方解释:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?tabs=aspnet ...

  5. asp.net core mvc 管道之中间件

    asp.net core mvc 管道之中间件 http请求处理管道通过注册中间件来实现各种功能,松耦合并且很灵活 此文简单介绍asp.net core mvc中间件的注册以及运行过程 通过理解中间件 ...

  6. ASP.NET CORE 管道模型及中间件使用解读

    说到ASP.NET CORE 管道模型不得不先来看看之前的ASP.NET 的管道模型,两者差异很大,.NET CORE 3.1 后完全重新设计了框架的底层,.net core 3.1 的管道模型更加灵 ...

  7. asp.net core 3.1 自定义中间件实现jwt token认证

    asp.net core 3.1 自定义中间件实现jwt token认证 话不多讲,也不知道咋讲!直接上代码 认证信息承载对象[user] /// <summary> /// 认证用户信息 ...

  8. 用UseMiddleware扩展方法注册中间件类

    用UseMiddleware扩展方法注册中间件类 .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件 ...

  9. Zepto 添加手势判断拓展方法(思路+原理)

    一.前言 这几个月事情比较多,写了一些博客都没有来得及整理发布,今天刚好有一位同事在开发前端页面的时候用到了手势判断.所以翻出了之前写的 demo,顺便整理一下作为记录. 手势判断在各种应用中都十分常 ...

随机推荐

  1. SQL常用条件操作符

    1.SQL的六类内容: (1)数据定义语言(DDL): 创建.删除表结构的语句,包括Create.Drop (2)数据控制语言(DCL): 为定义数据访问及修改权限而实现的语句,包括Grant.Rev ...

  2. [RHEL7.1]关闭防火墙及SElinux

    一.关闭防火墙 1. 先查看防火墙状态 [root@bogon ~]# 1 systemctl status firewalld firewalld.service - firewalld - dyn ...

  3. jquery的html代码中a的onclick的正确显示的代码

    jquery的html代码中a的onclick的正确显示的代码 需要转义一下,试了好久才试出来 img_delete.html('<a onclick="deleteImg(\''+s ...

  4. Java中权限设置

    package think_in_java_access_contorl; import think_in_java_access_contorl.access.Cookie; /** * 1.在Ja ...

  5. MyEclipse 配置Android环境

    eclipse https://www.eclipse.org/downloads/download.php?file=/oomph/epp/mars/R2/eclipse-inst-win64.ex ...

  6. VB中的正则表达式

    RegExp对象提供简单的正则表达式支持功能. RegExp对象的用法:Function RegExpTest(patrn, strng)Dim regEx, Match, Matches ' 建立变 ...

  7. 【Arduino】、Arduino+ESP8266上传至oneNet云

    一.硬件简介 1. Arudino 是一种开源的电子平台,该平台最初主要基于AVR单片机的微控制器和相应的开发软件,包含硬件(各种型号的Arduino板)和软件(Arduino IDE). 2. ES ...

  8. mysql 塞数据

    ./mysql_.py -H109.105.4.65 -P32773 -uroot -proot.123 --database=test_database --number=10 sysbench - ...

  9. $or操作符

    [$or操作符] The $or operator performs a logical OR operation on an array of two or more <expressions ...

  10. springMVC框架介绍以及运行流程(图解)

    1 Springmvc是什么? spring web mvc和struts2都属于表现层的框架,spring web mvc是spring框架的一部分(所以spring mvc与spring之间不需要 ...