












GBK,GB2312编码
<ItemGroup> <PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" /> </ItemGroup>
// System.Text.Encoding.CodePages
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var Encoding = Encoding.GetEncoding("GBK");
获取操作系统
#if NET6_0_OR_GREATER
OperatingSystem.IsWindows();
#else
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
#endif
OperatingSystem.IsBrowser();
.NET6忽略上传文件大小限制
builder.WebHost.UseKestrel(so =>
{
so.Limits.MaxRequestBodySize = null;
});
SQLite 加密,使用微软驱动可以实现加密,
普通的可视化工具不能打开,可以使用https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.12.2/DB.Browser.for.SQLite-3.12.2-win64.zip
dotnet remove package Microsoft.Data.Sqlite dotnet add package Microsoft.Data.Sqlite.Core dotnet add package SQLitePCLRaw.bundle_e_sqlcipher
隐式引用命名空间
<!--隐式引用命名空间-->
<ItemGroup Condition="'$(Language)' == 'C#' AND ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable')">
<Using Include="System" />
<Using Include="System.Linq" />
</ItemGroup>
<!--排除命名空间-->
<ItemGroup>
<Using Remove="Microsoft.AspNetCore.Builder" />
</ItemGroup>
模型绑定
绑定源不仅仅只有这一种:
建议大家在编写接口时,尽量显式指明绑定源。
集合入参绑定时
[FromQuery] string[] ids
可以采用以下格式之一:
此外,表单还可以支持一种格式:ids[]=1&ids[]=2
[FromQuery] Dictionary<int, string> idNames
可以采用以下格式之一:
docker下.net程序DateTime少8小时
可以在Dockerfile中添加
#修改时区,默认基于FROM镜像的时区
#Debian语法ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。