The poisoned code is as follows: void Main() { Value a = 0; if (a == 1 && a == 2 && a == 3) { Console.WriteLine("毒代码"); return; } Console.WriteLine("代码无毒"); } public class Value { private int _value; public Value() { } publi…

2021年9月25日 0条评论 2558点热度 0人点赞 痴者工良 阅读全文

下毒代码如下: void Main() { Value a = 0; if (a == 1 && a == 2 && a == 3) { Console.WriteLine("给代码下点毒"); return; } Console.WriteLine("代码无毒"); } public class Value { private int _value; public Value() { } public Value(int value) {[......]继续阅读

2021年9月25日 0条评论 2528点热度 0人点赞 痴者工良 阅读全文

The code provided exports a DataTable to a .csv format. public static async Task SaveCSV(DataTable dt,string[] header, string fileName) { StringBuilder sb = new StringBuilder(); sb.Append($"{string.Join(",", header)}\r\n"); for[......]继续阅读

2021年8月23日 0条评论 2702点热度 0人点赞 痴者工良 阅读全文

代码所示,将 Table 导出为 .csv 格式的数据。 public static async Task SaveCSV(DataTable dt,string[] header, string fileName) { StringBuilder sb = new StringBuilder(); sb.Append($"{string.Join(",", header)}\r\n"); for (int i = 0; i < dt.Rows.Count; i++)[......]继续阅读

2021年8月23日 0条评论 2672点热度 0人点赞 痴者工良 阅读全文

Inheriting from IActionResult: public class ResponseResult<TData> : IActionResult { /// <summary> /// Status code /// </summary> public int Code { get; set; } /// <summary> /// Response message /// </summary&[......]继续阅读

2021年8月21日 0条评论 4564点热度 0人点赞 痴者工良 阅读全文

继承 IActionResult: public class ResponseResult<TData> : IActionResult { /// <summary> /// 状态码 /// </summary> public int Code { get; set; } /// <summary> /// 响应信息 /// </summary> public string Msg { g[......]继续阅读

2021年8月21日 0条评论 4552点热度 0人点赞 痴者工良 阅读全文

There are readers suggesting to use app.UseExceptionHandler(); for global exception interception. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-9.0 The main difference lies in the middleware position when the request…

2021年8月12日 2条评论 3423点热度 0人点赞 痴者工良 阅读全文

有读者回复推荐全局异常拦截使用 app.UseExceptionHandler();。 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-9.0 跟本身的主要区别是请求到达的中间件位置不一样,对于整个 Web 链路生命周期,建议使用 app.UseExceptionHandler();。 本身主要关于 MVC 请求中的异常进行除了。 全局异常拦截器: /// <summary>…

2021年8月12日 2条评论 3443点热度 0人点赞 痴者工良 阅读全文

Directly use the .NET CLR library for generation without relying on third-party frameworks. The code has been updated to the latest implementation, removing deprecated interfaces. The Password-Based Key Derivation Function 2 (PBKDF2) makes it harder for others…

2021年8月12日 0条评论 108点热度 0人点赞 痴者工良 阅读全文

直接使用 .NET 的 CLR 库生成,不依赖第三方框架。 已将代码修正为最新实现,去掉过时接口。 基于密码的密钥导出函数2(PBKDF2)让别人更难通过穷举法猜到你的帐户密码。 pbkdf2 加密是不可逆的,因此可以用来处理密码等,只能对比,不能还原。 比如说,每个用户设置一个加密密钥,每个用户使用自己的密钥加密密码,且密码不可逆。 即使拿到一个用户的密码,破解了,每个用户的密钥都是不一样的,没法大规模爆破。 /// <summary> /// Pbkdf2 /// </summary> …

2021年8月12日 0条评论 3164点热度 0人点赞 痴者工良 阅读全文

When directly using the API to get a Claim, the correctness of the Token's key is not checked. var jwt = jwtSecurityTokenHandler.ReadJwtToken(token); If you want to check the Token at the same time, you can use the following: // Check the key ClaimsPr[......]继…

2021年8月12日 0条评论 82点热度 0人点赞 痴者工良 阅读全文

当直接使用 API 获取 Claim 时,是不会检查 Token 的密钥是否正确的。 var jwt = jwtSecurityTokenHandler.ReadJwtToken(token); 如果要同时检查 Token,则可以这样使用: // 检查密钥 ClaimsPrincipal claimsPrincipal = jwtSecurityTokenHandler.ValidateToken(token, new TokenValidationParameters[......]继续阅读

2021年8月12日 0条评论 2806点热度 0人点赞 痴者工良 阅读全文

Common JSON serialization configuration is as follows: // JSON serialization configuration private static readonly JsonSerializerOptions JsonSetting = new JsonSerializerOptions() { // First letter lowercase PropertyNamingPolicy = JsonNamingPolicy.Came[......]继…

2021年8月12日 0条评论 5007点热度 3人点赞 痴者工良 阅读全文

常用的 Json 序列化配置如下: // json 序列化配置 private static readonly JsonSerializerOptions JsonSetting = new JsonSerializerOptions() { // 首字母小写 PropertyNamingPolicy = JsonNamingPolicy.CamelCase, // 格式化输出,即自动换行、加上空格 WriteIndented = true,[......]继续阅读

2021年8月12日 0条评论 5048点热度 3人点赞 痴者工良 阅读全文

Middleware example: using AuthCenter.Domain.Modules; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace AuthCenter.Domain.Middlewares { /// <sum…

2021年8月12日 0条评论 2720点热度 0人点赞 痴者工良 阅读全文

中间件示例: using AuthCenter.Domain.Modules; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace AuthCenter.Domain.Middlewares { /// <summary> /// …

2021年8月12日 0条评论 2684点热度 0人点赞 痴者工良 阅读全文

Docker If you configure a Docker private repository using Nexus but do not set the correct address for Docker, you will receive the following error when pulling images: Error response from daemon: Get https://192.168.0.111:666/v2/: http: server gave HTTP respo…

2021年8月11日 0条评论 2661点热度 0人点赞 痴者工良 阅读全文

Docker 如果使用 Nexus 配置 Docker 私有仓库,但是 Docker 不配置好地址,那么拉取镜像时会提示: Error response from daemon: Get https://192.168.0.111:666/v2/: http: server gave HTTP response to HTTPS client 首先在 Nexus 上配置好 Docker 仓库。 例如下图,其端口是 8082。 因为使用的是 HTTP、HTTPS ,因此需要配置修改参数,打开 /etc/docker/…

2021年8月11日 0条评论 2623点热度 0人点赞 痴者工良 阅读全文

为了配置 Linux 免密登录,之前找到的方法都是比较麻烦的,后面发现一种只需要两个步骤就能完成免密登录配置的方法。 假如,在 Linux A 免密登录 Linux B。 那么在 A 上生成 私钥公钥: ssh-keygen 生成后,将公钥推送到 B 中: ssh-copy-id <user>@<ip> # 或者 scp /root/.ssh/id_rsa.pub <user>@<ip>:/root/.ssh/authorized_keys 接着首次输入密码. 然后会…

2021年8月4日 0条评论 78点热度 1人点赞 痴者工良 阅读全文

为了配置 Linux 免密登录,之前找到方法都是比较麻烦的,后面发现一种只需要两个步骤就能完成免密登录配置的方法。 假如,在 Linux A 免密登录 Linux B。 那么在 A 上生成 私钥公钥: ssh-keygen 生成后,将公钥推送到 B 中: ssh-copy-id <user>@<ip> # 或者 scp /root/.ssh/id_rsa.pub <user>@<ip>1:/root/.ssh/authorized_keys 接着首次输入密码. 然后会…

2021年8月4日 0条评论 3171点热度 1人点赞 痴者工良 阅读全文
1202122232454