NetBlog主题

.net 5.0获取客户端IP
.Net Core

.net 5.0获取客户端IP

2229

相关视频教程 https://www.bilibili.com/video/BV1LM4y1V7Am(如果不会请看我录制的视频教程)1、在Startup类里面 注册服务,如下图services.AddSingletonIHttpContextAccessor, HttpContextAccessor();2、在控制器里面获取ip 方法如下HttpContextAccessor context = new Ht…

.Net Core对MongoDB数据库增删改查
.Net Core

.Net Core对MongoDB数据库增删改查

2334

//实体类public class User{//转载请保留 http://www.luofenming.com/show.aspx?id=ART2021021300001 public MongoDB.Bson.ObjectId Id { get; set; } public string name { get; set; } public int age { get; set; }}//using MongoDB.Bson;//using MongoDB…

.net core/.net 5.0 API接口 线程阻塞异常
.Net Core

.net core/.net 5.0 API接口 线程阻塞异常

2547

不能直接在API接口里面用 System.Threading.Thread.Sleep阻塞线程,如果需要延时,要用异步处理。今天碰到这样的一个坑 在win 10 和 windows server 2008 没问题,但在windows server 2019 就出现以下问题An error occurred while processing your request.//错误的写法[Rou…

.net Core 3.1添加UEditor富文本编辑器(包含源码)
.Net Core

.net Core 3.1添加UEditor富文本编辑器(包含源码)

4595

视频讲解地址 https://www.bilibili.com/video/BV1jV4y1E7wv大致添加内容如下UEditorController控制器代码public class UEditorController : Controller{private readonly UEditorService _ueditorService;public UEditorController(UEditorService ueditorService){this._u…

解决 .net Core 3.1中使用GB2312编码异常
.Net Core

解决 .net Core 3.1中使用GB2312编码异常

6557

在.net core使用GB2312时抛出以下异常 System.ArgumentException:“'gb2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. 解决方法 在NuGet 添加“System.Text.Enco…

asp.net Core自定义 管道中间件
.Net Core

asp.net Core自定义 管道中间件

2544

整个 asp.Net Core应用都是在 管道中运行的,管道中放的都是中间件。下面是自定义中间件的两种方法方法一 public class TestMiddleware {//转载请保留 http://www.luofenming.com/show.aspx?id=ART2020021200001private readonly RequestDelegate _next;public TestMiddlewar…

.net Core 实现web网站图片防盗连接源码实例
.Net Core

.net Core 实现web网站图片防盗连接源码实例

2446

这里我用的是.net Core 3.1 以下是核心代码public class RefuseStealingMiddleWare{//转载请保留http://www.luofenming.com/show.aspx?id=ART2020021000001private readonly RequestDelegate _next;public RefuseStealingMiddleWare(RequestDelegate next){_next = next;}p…

.net Core基于ServiceStack Redis实现秒杀防超卖功能
.Net Core

.net Core基于ServiceStack Redis实现秒杀防超卖功能

3787

完整代码链接:https://pan.baidu.com/s/1wjmBtHhVhthNNnDCFU6hKA 提取码:bg51核心代码class OversellTest {//转载请保留http://www.luofenming.com/show.aspx?id=ART2020010500003private static bool IsGoOn = true;//秒杀活动是否结束public static void Show(){using (R…

.net Core 增删改查Redis,添加Redis数据过期时间
.Net Core

.net Core 增删改查Redis,添加Redis数据过期时间

4723

Redis: REmote DIctionary Server 远程字典(内存)服务器,基于内存管理(数据全部存在内存),实现了多种数据结构的,单线程模型的应用程序,提供插入-查询-固化-集群功能。Redis特点:速度快,数据可能丢失,只能做缓存,而不是存储。以下核心代码(这里采用的是StackExchange)…