随笔分类 - .NetCore
.net动态类ExpandoObject及使用场景
摘要:它位于 System.Dynamic 命名空间中。与普通的 C# 类型不同,ExpandoObject 允许在运行时动态地添加、删除或修改其成员(属性或方法)。这使得它在一些需要高度灵活性和动态性的数据结构场景中非常有用。ExpandoObject 的基本特性动态成员访问:可以在运行时添加或移除属性
阅读全文
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查询对象时没有
阅读全文
.NET压缩zip、.NET解压zip
摘要:参考:https://blog.csdn.net/zhaotianff/article/details/141156035 using System.IO.Compression; namespace XCG.Commons { public class ZipUtil { /// <summary
阅读全文
.NetCore里使用定时任务BackgroundService
摘要:原文链接:https://blog.csdn.net/x1234w4321/article/details/140797306 namespace XCGWebApp.TimerService { /// <summary> /// 后台定时任务 /// </summary> public clas
阅读全文
.net跳过某一个中间件,在中间件中获取自定义注解Attribute进行判断。
摘要:逻辑:增加一个自定义注解Attribute,在中间件中判断注解中是否配置了跳过该中间件,跳过则直接await _next(httpContext);主要是在中间件中获取自定义注解。自定义注解 namespace XCGWebApp.Attributes { [AttributeUsage(Attri
阅读全文
nginx配置负载均衡,nginx负载均衡404错误
摘要:nginx在nginx.conf配置文件中通过upstream模块和server模块的配合使用,就可以实现负载均衡。在http的 upstream模块中,可以通过 server指令指定后端服务器的IP地址和端口,同时还可以设定每个后端服务器在负载均衡调度中的状态。常用的状态有:weight:服务访问
阅读全文
.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
阅读全文
.net使用Task多线程执行任务 .net限制线程数量
摘要:k using System.Text.Json; namespace WinFormsApp { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } /// <summary> //
阅读全文
.net8 winform程序使用EntityFrameworkCore连接数据库
摘要:在.NET 8 WinForms应用程序中使用Entity Framework (EF) Core,你需要按照以下步骤操作:1.添加Entity Framework Core NuGet包。2.定义你的数据模型。3.创建数据库上下文 (DbContext)。4.在数据库上下文中配置Entity Fr
阅读全文
.net删除目录以及目录内所有文件
摘要:看 using System.IO; public static void DeleteDirectory(string targetDir) { string[] files = Directory.GetFiles(targetDir); string[] dirs = Directory.Ge
阅读全文
NSSM安装windows服务配置项说明
摘要:官网下载地址:https://nssm.cc/download配置项说明:Path:运行应用程序的程序Startup directory:应用程序所在的目录Arguments:应用运行的参数Service name:生成服务的名称最后点击install service 完成windows服务安装,在
阅读全文
Cron表达式
摘要:原文链接:https://blog.csdn.net/troubleshooter/article/details/119389179Cron表达式是一个字符串,以5个或6个空格隔开,分为6个或7个域,每一个域代表一个含义,Cron有如下两种语法格式:1.Seconds Minutes Hours
阅读全文
.net mysql连接字符串中指定数据库字符集,排序规则没法指定collation=utf8mb4_general_ci
摘要:连接字符串 server=localhost;port=3306;database=xcgdb;uid=root;pwd=root;charset=utf8mb4;新版Mysql8在创建数据库的时候自己设置想要的排序规则。如果是使用migration自动创建的话,使用Mysql8的默认排序规则 ut
阅读全文
.net core上传文件、.net core接收文件上传
摘要:我要做一个winform程序,上传文件到.net8的文件上传接口winform /// <summary> /// 选择图片上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private
阅读全文
.net输出文件到浏览器,.net下载文件
摘要:放 // 使用FileStream读取文件 using (FileStream fileStream = new FileStream(localDestZipFullName, FileMode.Open, FileAccess.Read)) { // 创建一个内存流 using (MemoryS
阅读全文
.NET Core放开文件目录并指定访问路径app.UseStaticFiles();
摘要:在Program.cs中加入配置 app.UseStaticFiles(); // 在这里,我们指定了自定义的静态文件目录 "/custom-static" app.UseStaticFiles(new StaticFileOptions { FileProvider = new Microsoft
阅读全文
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,*/*;
阅读全文
.net api接口接收字符串或者xml,.NET发送xml请求
摘要:看 using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc; using XCGWebApp.Dtos; using XCGWebApp.Common; using System.Text; namespace XCGWebApp
阅读全文
.net core 如何在中间件中获取自定义的特性
摘要:来源:https://blog.csdn.net/lwplvx/article/details/113614095 var endpoint = httpContext.GetEndpoint(); if (endpoint != null) { var permissionAttribute =
阅读全文
.net core、.net8中间件中不能注入Service服务,报错:Cannot resolve scoped service 'XXX' from root provider
摘要:中间件中如果想用Service服务,不能用注入,需要这样写: using (var serviceCope = httpContext.RequestServices.CreateScope()) { ISysSettingService? _sysSettingService = serviceC
阅读全文