.net 5.0获取客户端IP
相关视频教程 https://www.bilibili.com/video/BV1LM4y1V7Am(如果不会请看我录制的视频教程)1、在Startup类里面 注册服务,如下图services.AddSingletonIHttpContextAccessor, HttpContextAccessor();2、在控制器里面获取ip 方法如下HttpContextAccessor context = new Ht…
相关视频教程 https://www.bilibili.com/video/BV1LM4y1V7Am(如果不会请看我录制的视频教程)1、在Startup类里面 注册服务,如下图services.AddSingletonIHttpContextAccessor, HttpContextAccessor();2、在控制器里面获取ip 方法如下HttpContextAccessor context = new Ht…
//实体类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…
不能直接在API接口里面用 System.Threading.Thread.Sleep阻塞线程,如果需要延时,要用异步处理。今天碰到这样的一个坑 在win 10 和 windows server 2008 没问题,但在windows server 2019 就出现以下问题An error occurred while processing your request.//错误的写法[Rou…
视频讲解地址 https://www.bilibili.com/video/BV1jV4y1E7wv大致添加内容如下UEditorController控制器代码public class UEditorController : Controller{private readonly UEditorService _ueditorService;public UEditorController(UEditorService ueditorService){this._u…
在.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应用都是在 管道中运行的,管道中放的都是中间件。下面是自定义中间件的两种方法方法一 public class TestMiddleware {//转载请保留 http://www.luofenming.com/show.aspx?id=ART2020021200001private readonly RequestDelegate _next;public TestMiddlewar…
这里我用的是.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…
完整代码链接: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…
Redis: REmote DIctionary Server 远程字典(内存)服务器,基于内存管理(数据全部存在内存),实现了多种数据结构的,单线程模型的应用程序,提供插入-查询-固化-集群功能。Redis特点:速度快,数据可能丢失,只能做缓存,而不是存储。以下核心代码(这里采用的是StackExchange)…
结构图Program类代码 public class Program {public static void Main(string[] args){CreateHostBuilder(args).Build().Run();}public static IHostBuilder CreateHostBuilder(string[] args) =>Host.CreateDefaultBuilder(args).ConfigureAppConfiguration(conf =>{conf.Add…