随笔分类 -  .net core

摘要:1 为什么需要使用ioc 细节还会依赖细节。 使用ioc的话,以三层架构为例,当数据访问层(dal)层改变后,业务逻辑层(bll)也得改,甚至表示层(ui)也要改,使用ioc后dal层的改变不会影响其它层 自动注入(通过反射):如果1个对象的构造函数参数有多个,每个参数的构造函数又依赖其他参数,你需 阅读全文
posted @ 2023-11-19 11:27 温故纳新 阅读(93) 评论(0) 推荐(0) 编辑
摘要:dotnet run --urls "http://localhost:13102" 注意是在web api启动项目文件夹下 需要访问 http://localhost:13102/swagger/index.html ,访问 http://localhost:13102报 404 阅读全文
posted @ 2023-02-17 17:20 温故纳新 阅读(237) 评论(0) 推荐(0) 编辑
摘要:1 appsettins 配置 { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "Theme": { "Name": 阅读全文
posted @ 2023-02-14 17:12 温故纳新 阅读(219) 评论(1) 推荐(0) 编辑
摘要:1 新建 .net 6 webapi 项目 2 安装nuget包 log4net 3 新建工具类 Log4NetUtil 添加引用 using System.IO;using log4net;using log4net.Config;using log4net.Repository; public 阅读全文
posted @ 2022-06-15 17:04 温故纳新 阅读(1416) 评论(0) 推荐(0) 编辑
摘要:1 编写 ConsulServerOptions 类 public class ConsulServerOptions { public string? IP { get; set; } public int Port { get; set; } public string? Datacenter 阅读全文
posted @ 2022-06-03 10:13 温故纳新 阅读(100) 评论(0) 推荐(0) 编辑
摘要:1 在Startup中添加 public Startup(IWebHostEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appse 阅读全文
posted @ 2022-06-03 10:12 温故纳新 阅读(413) 评论(0) 推荐(0) 编辑
摘要:1 创建 .net5 web api 项目 2 修改 Startup.cs 如下 using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolic 阅读全文
posted @ 2022-05-20 17:06 温故纳新 阅读(376) 评论(0) 推荐(0) 编辑
摘要:在 Startup.cs 中的 Configure 方法中添加如下代码: app.UseDefaultFiles(); if (!Directory.Exists(Directory.GetCurrentDirectory() + "/wwwroot")) Directory.CreateDirec 阅读全文
posted @ 2022-05-05 11:59 温故纳新 阅读(471) 评论(0) 推荐(0) 编辑
摘要:跨域报错如下:https://localhost:44373 发起请求,请求 https://localhost:5001/api/HomeApi/GetData 接口数据 其中:origin(https://localhost:44373) 的发起请求的请求方,https://localhost: 阅读全文
posted @ 2022-04-22 10:23 温故纳新 阅读(436) 评论(0) 推荐(0) 编辑
摘要:1 在 Startup.cs 添加服务和配置中间件 在 Startup.cs 的 ConfigureServices 添加如下代码: services.AddResponseCaching(options => { options.SizeLimit = 100 * 1024 * 1024; // 阅读全文
posted @ 2022-01-23 22:07 温故纳新 阅读(154) 评论(0) 推荐(0) 编辑
摘要:选项模式使用类来提供对相关设置组的强类型访问 1 创建 asp.net core mvc5 项目 在项目中添加如下引用: Microsoft.Extensions.Configuration.Json 2 创建 json 配置文件 testData.json 并把该文件属性“复制到输出目录”设置为“ 阅读全文
posted @ 2022-01-17 10:32 温故纳新 阅读(82) 评论(0) 推荐(0) 编辑
摘要:一 通过实现 IActionFilter 实现自定义过滤器 1 自定义过滤器对应的特性 public class ImpIActionFilterDescAttribute : Attribute { public string Code { get; set; } public string De 阅读全文
posted @ 2021-08-23 17:08 温故纳新 阅读(328) 评论(0) 推荐(0) 编辑
摘要:解决方法:开启运行时编译 1 在现有项目中 nuget 添加引用 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 然后在 Startup.cs 的ConfigureServices 中 添加 如下代码 services.AddRazorPages( 阅读全文
posted @ 2021-08-20 14:18 温故纳新 阅读(513) 评论(0) 推荐(0) 编辑
摘要:项目总体文件结构 1 在项目中新建 Areas 文件夹2 在 Areas 文件夹中新建 Orders 和 Products 文件夹3 在 Orders 和 Products 文件夹下分别新建 Controllers 和 Views 文件夹4 分别在 Orders 和 Products 文件夹下的 C 阅读全文
posted @ 2021-08-20 13:57 温故纳新 阅读(96) 评论(0) 推荐(0) 编辑
摘要:1 修改Program.cs 如下 public class Program { public static void Main(string[] args) { // Create the Serilog logger, and configure the sinks Log.Logger = n 阅读全文
posted @ 2021-07-21 09:20 温故纳新 阅读(317) 评论(0) 推荐(0) 编辑
摘要:1 在项目中添加 hosting.json 文件用来配置端口,内容如下 { "urls": "http://*:12306" } 修改启动项目 Program.cs 文件 Main 方法如下 public class Program { public static void Main(string[ 阅读全文
posted @ 2021-07-18 17:30 温故纳新 阅读(393) 评论(0) 推荐(0) 编辑
摘要:1 在服务器上安装 托管捆绑包 安装 .net 5.0 版本的捆绑包 dotnet-hosting-5.0.7-win 链接:https://pan.baidu.com/s/1P7neU8xJtXe0Neu8sv-Dpg 提取码:qgga 2 使用visual studio 生成发布包。 如果部署模 阅读全文
posted @ 2021-07-10 12:19 温故纳新 阅读(204) 评论(0) 推荐(0) 编辑
摘要:1 使用 nuget 安装 Serilog.AspNetCore 包 2 在 Program.cs 中 添加以下引用 using Serilog; using Serilog.Formatting.Compact;using Serilog.Events; 3 在 Program.cs 中方法 Cr 阅读全文
posted @ 2021-06-26 11:39 温故纳新 阅读(462) 评论(1) 推荐(0) 编辑

点击右上角即可分享
微信分享提示