随笔分类 -  .NetCore

.net动态类ExpandoObject及使用场景
摘要:它位于 System.Dynamic 命名空间中。与普通的 C# 类型不同,ExpandoObject 允许在运行时动态地添加、删除或修改其成员(属性或方法)。这使得它在一些需要高度灵活性和动态性的数据结构场景中非常有用。ExpandoObject 的基本特性动态成员访问:可以在运行时添加或移除属性 阅读全文
posted @ 2024-11-13 16:26 邢帅杰 阅读(592) 评论(0) 推荐(0)
The instance of entity type 'xxx' cannot be tracked because another instance with the same key value for {'xxx'} is already being tracked.
摘要:参考:https://blog.csdn.net/qq_18638761/article/details/107833999https://www.cnblogs.com/stgp/p/12294454.html发生的原因,在CheckProductionCode()方法中根据主键id查询对象时没有 阅读全文
posted @ 2024-10-16 13:55 邢帅杰 阅读(187) 评论(0) 推荐(0)
.NET压缩zip、.NET解压zip
摘要:参考:https://blog.csdn.net/zhaotianff/article/details/141156035 using System.IO.Compression; namespace XCG.Commons { public class ZipUtil { /// <summary 阅读全文
posted @ 2024-10-14 10:04 邢帅杰 阅读(31) 评论(0) 推荐(0)
.NetCore里使用定时任务BackgroundService
摘要:原文链接:https://blog.csdn.net/x1234w4321/article/details/140797306 namespace XCGWebApp.TimerService { /// <summary> /// 后台定时任务 /// </summary> public clas 阅读全文
posted @ 2024-08-22 11:29 邢帅杰 阅读(134) 评论(0) 推荐(0)
.net跳过某一个中间件,在中间件中获取自定义注解Attribute进行判断。
摘要:逻辑:增加一个自定义注解Attribute,在中间件中判断注解中是否配置了跳过该中间件,跳过则直接await _next(httpContext);主要是在中间件中获取自定义注解。自定义注解 namespace XCGWebApp.Attributes { [AttributeUsage(Attri 阅读全文
posted @ 2024-08-21 16:23 邢帅杰 阅读(30) 评论(0) 推荐(0)
nginx配置负载均衡,nginx负载均衡404错误
摘要:nginx在nginx.conf配置文件中通过upstream模块和server模块的配合使用,就可以实现负载均衡。在http的 upstream模块中,可以通过 server指令指定后端服务器的IP地址和端口,同时还可以设定每个后端服务器在负载均衡调度中的状态。常用的状态有:weight:服务访问 阅读全文
posted @ 2024-06-24 11:12 邢帅杰 阅读(619) 评论(0) 推荐(0)
.net使用Task多线程获取返回值/.net设置Task超时时间/CancellationTokenSource用法
摘要:参考:https://www.jb51.net/article/237222.htm//不卡主线程,获取返回值。List<Task<int>> tasks = new List<Task<int>>();tasks.Add(Task.Run(()=>{return 1;}));//返回的是一个int 阅读全文
posted @ 2024-05-22 15:23 邢帅杰 阅读(231) 评论(0) 推荐(0)
.net使用Task多线程执行任务 .net限制线程数量
摘要:k using System.Text.Json; namespace WinFormsApp { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } /// <summary> // 阅读全文
posted @ 2024-05-21 15:50 邢帅杰 阅读(177) 评论(0) 推荐(0)
.net8 winform程序使用EntityFrameworkCore连接数据库
摘要:在.NET 8 WinForms应用程序中使用Entity Framework (EF) Core,你需要按照以下步骤操作:1.添加Entity Framework Core NuGet包。2.定义你的数据模型。3.创建数据库上下文 (DbContext)。4.在数据库上下文中配置Entity Fr 阅读全文
posted @ 2024-05-21 11:52 邢帅杰 阅读(1443) 评论(0) 推荐(0)
.net删除目录以及目录内所有文件
摘要:看 using System.IO; public static void DeleteDirectory(string targetDir) { string[] files = Directory.GetFiles(targetDir); string[] dirs = Directory.Ge 阅读全文
posted @ 2024-05-17 11:12 邢帅杰 阅读(169) 评论(0) 推荐(0)
NSSM安装windows服务配置项说明
摘要:官网下载地址:https://nssm.cc/download配置项说明:Path:运行应用程序的程序Startup directory:应用程序所在的目录Arguments:应用运行的参数Service name:生成服务的名称最后点击install service 完成windows服务安装,在 阅读全文
posted @ 2024-05-15 10:49 邢帅杰 阅读(596) 评论(0) 推荐(0)
Cron表达式
摘要:原文链接:https://blog.csdn.net/troubleshooter/article/details/119389179Cron表达式是一个字符串,以5个或6个空格隔开,分为6个或7个域,每一个域代表一个含义,Cron有如下两种语法格式:1.Seconds Minutes Hours 阅读全文
posted @ 2024-05-06 10:25 邢帅杰 阅读(82) 评论(0) 推荐(0)
.net mysql连接字符串中指定数据库字符集,排序规则没法指定collation=utf8mb4_general_ci
摘要:连接字符串 server=localhost;port=3306;database=xcgdb;uid=root;pwd=root;charset=utf8mb4;新版Mysql8在创建数据库的时候自己设置想要的排序规则。如果是使用migration自动创建的话,使用Mysql8的默认排序规则 ut 阅读全文
posted @ 2024-04-26 17:52 邢帅杰 阅读(43) 评论(0) 推荐(0)
.net core上传文件、.net core接收文件上传
摘要:我要做一个winform程序,上传文件到.net8的文件上传接口winform /// <summary> /// 选择图片上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private 阅读全文
posted @ 2024-03-26 10:23 邢帅杰 阅读(433) 评论(0) 推荐(0)
.net输出文件到浏览器,.net下载文件
摘要:放 // 使用FileStream读取文件 using (FileStream fileStream = new FileStream(localDestZipFullName, FileMode.Open, FileAccess.Read)) { // 创建一个内存流 using (MemoryS 阅读全文
posted @ 2024-03-15 09:57 邢帅杰 阅读(74) 评论(0) 推荐(0)
.NET Core放开文件目录并指定访问路径app.UseStaticFiles();
摘要:在Program.cs中加入配置 app.UseStaticFiles(); // 在这里,我们指定了自定义的静态文件目录 "/custom-static" app.UseStaticFiles(new StaticFileOptions { FileProvider = new Microsoft 阅读全文
posted @ 2024-03-15 09:08 邢帅杰 阅读(194) 评论(0) 推荐(0)
Http请求头 application/xml和text/xml
摘要:Accept:指定客户端能够接收的内容类型,内容类型中的先后次序表示客户端接收的先后次序。 实例:Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*; 阅读全文
posted @ 2024-03-12 10:09 邢帅杰 阅读(919) 评论(0) 推荐(0)
.net api接口接收字符串或者xml,.NET发送xml请求
摘要:看 using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc; using XCGWebApp.Dtos; using XCGWebApp.Common; using System.Text; namespace XCGWebApp 阅读全文
posted @ 2024-03-08 15:39 邢帅杰 阅读(477) 评论(0) 推荐(0)
.net core 如何在中间件中获取自定义的特性
摘要:来源:https://blog.csdn.net/lwplvx/article/details/113614095 var endpoint = httpContext.GetEndpoint(); if (endpoint != null) { var permissionAttribute = 阅读全文
posted @ 2024-02-05 17:19 邢帅杰 阅读(211) 评论(0) 推荐(0)
.net core、.net8中间件中不能注入Service服务,报错:Cannot resolve scoped service 'XXX' from root provider
摘要:中间件中如果想用Service服务,不能用注入,需要这样写: using (var serviceCope = httpContext.RequestServices.CreateScope()) { ISysSettingService? _sysSettingService = serviceC 阅读全文
posted @ 2024-02-05 17:11 邢帅杰 阅读(311) 评论(0) 推荐(0)