# 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. 「小程序JAVA实战」小程序视频播放的时候生命周期的控制(56)

    转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxushipinbofangdeshihoushengmingzhouqi ...

  2. Eclipse使用xdoclet1.2.3 生成hibernate配置文件和映射文件

    用ant和xdoclet生成hibernate配置文件可以为我们省去很多配置的操作,废话不多说,直接给栗子: 测试环境: eclipse:Eclipse Java EE IDE for Web Dev ...

  3. Liunx cannot remove `xxx': Operation not permitted

    链接: http://mangocool.com/detail_1_1439515930283.html 解到原来文件还可以设置隐藏权限,就是这个chattr设置,下面我们来看看这个命令的详解. [r ...

  4. Tutorial: Getting Started with Spring Security

    This tutorial will cover a basic scenario where it  integrates Spring Security, using database-backe ...

  5. 迷你MVVM框架 avalonjs 0.98发布

    在本版本中,avalon侧重于对组件开发的支持,可用控件达到12个,末来将大力投入对GRID,TREE等重型UI的开发中. 添加ms-widget绑定,废弃ms-ui绑定 为ms-include添加跨 ...

  6. linux 正则表达式

    redis-cli INFO|tr -d '\r'|egrep -v '^(#.*)?$'|sed -E 's/^([^:]*):(.*)$/redisInfo[\1]="\2"/ ...

  7. Python与Go快速排序

    #!/usr/bin/env python # -*- coding: utf-8 -*- # 快速排序 # 时间复杂度 O(n lgn)-- O(n^2) def quick_sort(array) ...

  8. Python运维开发基础05-语法基础

    上节作业回顾(讲解+温习90分钟) #!/usr/bin/env python # -*- coding:utf-8 -*- # author:Mr.chen import os,time Tag = ...

  9. better-scroll的用法,及其中的一个属性event._constructed详解

    better-scroll是一个页面滚动插件,用它可以很方便的实现下拉刷新,锚点滚动等功能. 实现原理:父容器固定高度,并设置overflow:hidden,子元素超出父元素高度后将被隐藏,超出部分可 ...

  10. jquery中的trigger()和preventDefault()方法

    trigger()方法用户模拟用户操作,比较常见的一种情况就是输入框自动获得焦点: <!doctype html> <html> <head> <meta c ...