最近项目有个新同事,每个API接口里返回的时间格式中都带T如:【2019-06-06T10:59:51.1860128+08:00】,其实这个主要是ASP.Net Core自带时间格式列化时间格式设置的,我们只需要替换序格式化时间格式就可以; 一、先建一个控制器测试:
1 2 3 4 5 6 7 8 9 10 |
public IActionResult Get() { UserInfo userInfo = new UserInfo() { Name = "lxsh", BirthDay = DateTime.Now }; return Ok(userInfo); } |
二、没有替换格式化时间之前效果: 三、可以在注入mvc服务的时候设置格式化参数,在Startup类的ConfigureServices方法中指定
1 2 3 4 |
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(options => { options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; }); |
四、替换后的格式时间效果如下: from:https://www.cnblogs.com/lxshwyan/p/10983974.html
View Details【问题】网站 项目里经常用到DateTime类型变量,要求所有日期时间类型格式标准为“yyyy-MM-dd HH:mm:ss”,但默认Tostring格式为 yyyy-M-d H:m:s ,没有前置0, 需要修改 【分析】 1、修改代码里所有DateTime类型的Tostring为 ToString("yyyy-MM-dd HH:mm:ss"),不方便 2、找见统一的修改地方, Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN", true) { DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd", FullDateTimePattern = "yyyy-MM-dd HH:mm:ss" }; 发现不起作用 经分析DateTimeFormat 类的属性,发现 LongTimePattern 起作用 【结论】 增加 LongTimePattern 属性
1 2 3 |
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN", true) { DateTimeFormat = { ShortDatePattern = "yyyy-MM-dd", FullDateTimePattern = "yyyy-MM-dd HH:mm:ss", LongTimePattern ="HH:mm:ss"} }; |
from:https://blog.csdn.net/onemetre/article/details/52042907
View Details把终端显示改为英文: 1、先备份语言配置文件 cp /etc/locale.conf /home/locale.conf.backup 2、打开配置文件 vim /etc/locale.conf 3、把“zh_CN.UTF-8”修改为“en_US.UTF-8” 4、esc :wq 保存并退出 5、shutdown -r now 重启 from:https://www.cnblogs.com/nnniki/p/10359229.html
View Details1、从微软下载net core https://download.visualstudio.microsoft.com/download/pr/dd164132-d4c4-4c1a-8233-a4fc7e157935/bffa5312d613cab1a14f0858f947a6fc/dotnet-runtime-2.1.11-linux-x64.tar.gz 2、将安装包上传至linux中 3、解压 tar -vxf dotnet-runtime-2.1.11-linux-x64.tar.gz 4、创建链接,使所有目录下都可以访问到dotnet命令(这里是解压后放在/home/dotnetcore目录下) ln -s /home/dotnetcore/dotnet /usr/local/bin 5、测试验证是否成功 任意目录下:dotnet --info 最后,使用dotnet+dll名称,测试软件是否可以运行,如果无法运行,则安装相应的软件包即可 参考: 1、.NET Core 指南:https://docs.microsoft.com/zh-cn/dotnet/core/ 2、net core下载中心:https://dotnet.microsoft.com/download/dotnet-core from:https://blog.csdn.net/dqcoffee/article/details/91353543
View Details在部署的时候,如果您不想在您的Linux服务器上安装.Net Core SDK,您可以只安装Runtime,接下来我们看看该如何安装运行时Runtime。 下载运行时文件 下载页面:https://www.microsoft.com/net/download/linux 先获取一下对应的下载链接,可以使用浏览器点击链接来获取具体文件的下载链接 获取完链接以后,就可以使用命令下获取和安装了 以Centos 7,Ubuntu 16.04为例安装ASP.Net Core 2.0.5的运行时:
1 2 3 4 5 |
wget -O dotnet-runtime.tar.gz https://download.microsoft.com/download/1/1/0/11046135-4207-40D3-A795-13ECEA741B32/dotnet-runtime-2.0.5-linux-x64.tar.gz wget -O aspnetcore-store.tar.gz https://download.microsoft.com/download/1/1/0/11046135-4207-40D3-A795-13ECEA741B32/aspnetcore-store-2.0.5-linux-x64.tar.gz mkdir dotnet tar zxf dotnet-runtime.tar.gz -C dotnet tar zxf aspnetcore-store.tar.gz -C dotnet |
还需要安装 libunwind Centos 7
1 |
yum update -y && yum install libunwind libicu -y |
Ubuntu 16.04
1 |
apt-get update -y && apt-get install libunwind-dev -y |
原文地址:https://www.zkea.net/codesnippet/detail/post-85 from:https://www.cnblogs.com/seriawei/p/8438126.html
View Details最近在技术博客和技术交流群遇到很多小伙伴们在Linux下更新或者安装.Net Core SDK后dotnet命令无法识别等问题,现如下解决: 卸载SDK命令
1 |
sudo yum remove dotnet-sdk-* |
1 |
sudo yum remove libunwind libicu |
1 |
sudo yum remove /etc/yum.repos.d/dotnetdev.repo |
从新安装即可 from:https://www.cnblogs.com/yangzhili/p/9217083.html
View DetailsCentOS修改IP地址 # ifconfig eth0 192.168.1.80 这样就把IP地址修改为192.168.1.80(如果发现上不了网了,那么你可能需要把网关和DNS也改一下,后面会提到),但是当你重新启动系统或网卡之后,还是会变回原来的地址,这种修改方式只适用于需要临时做IP修改。要想永久性修改,就要修改/etc/sysconfig/network-scripts/ifcfg-eth0这个文件,这个文件的主要内容如下(你的文件中没有的项,你可以手动添加): # vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名 BOOTPROTO=static #设置网卡获得ip地址的方式,选项可以为为static,dhcp或bootp BROADCAST=192.168.44.255 #对应的子网广播地址 HWADDR="00:0C:29:6B:2E:7B"#对应的网卡物理地址 IPADDR=192.168.44.137 #只有网卡设置成static时,才需要此字段 NETMASK=255.255.255.0 #网卡对应的网络掩码 NETWORK=192.168.44.0 #网卡对应的网络地址,也就是所属的网段 ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备 CentOS修改网关 # route add default gw 192.168.1.1 dev eth0 这样就把网关修改为192.168.1.1了,这种修改只是临时的,当你重新启动系统或网卡之后,还是会变回原来的网关。要想永久性修改,就要修改/etc/sysconfig/network 这个文件,这个文件的主要内容如下(你的文件中没有的项,你可以手动添加): # vi /etc/sysconfig/network NETWORKING=yes #表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络。 HOSTNAME=centos #设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应 GATEWAY=192.168.1.1 #设置本机连接的网关的IP地址。 **********上面的文件修改完要重新启动一下网卡才会生效:# service network restart ******** CentOS修改DNS 上面的都修改完之后,当你ping一个域名是肯能不通,但ping对应的IP地址是同的,这时我们需要修改一下DNS。修改DNS要通过修改/etc/resolv.conf这个文件: # vi /etc/resolv.conf nameserver 8.8.8.8 #google域名服务器 nameserver 8.8.4.4 #google域名服务器 通过上面的所有设置,系统应该可以上网了。 如果centos系统建立在虚拟机之上,那么在设置虚拟机的网络时请选择‘网桥适配器’连接。 from:https://www.cnblogs.com/liuys635/p/11335594.html
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
2019-05-09 10:27:01,330 线程ID:[80] 日志级别:ERROR 出错类:WebApp.HttpGlobalExceptionFilter property:[(null)] - 错误描述:System.TypeInitializationException: The type initializer for 'System.DrawingCore.GDIPlus' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'gdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgdiplus: cannot open shared object file: No such file or directory at System.DrawingCore.GDIPlus.GdiplusStartup(UInt64& token, GdiplusStartupInput& input, GdiplusStartupOutput& output) at System.DrawingCore.GDIPlus..cctor() --- End of inner exception stack trace --- at System.DrawingCore.GDIPlus.GdipGetGenericFontFamilySansSerif(IntPtr& fontFamily) at System.DrawingCore.FontFamily..ctor(GenericFontFamilies genericFamily) at System.DrawingCore.FontFamily.get_GenericSansSerif() at System.DrawingCore.Font.CreateFont(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical) at Common.VerifyCodeHelper.CreateByteByImgVerifyCode(String verifyCode, Int32 width, Int32 height) in F:\src\WebApp\Common\VerifyCodeHelper.cs:line 206 at WebApp.Controllers.VerifyCodeController.NumberVerifyCode() in F:\src\WebApp\Controllers\VerifyCodeController.cs:line 27 at lambda_method(Closure , Object , Object[] ) at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync() |
解决方法 Centos 7 yum install libgdiplus-devel from:https://www.cnblogs.com/asd14828/p/10837140.html?utm_source=tuicool
View Details通过 Opw.HttpExceptions.AspNetCore 搞定了。 1)安装 nuget 包 Opw.HttpExceptions.AspNetCore
1 |
<PackageReference Include="Opw.HttpExceptions.AspNetCore" Version="2.3.0" /> |
2)Startup.ConfigureServices 中添加 AddHttpExceptions
1 |
services.AddControllers().AddHttpExceptions(); |
3)Startup.Configure 中添加 UseHttpExceptions
1 |
app.UseHttpExceptions(); |
示例响应输出
1 |
{"type":"error:invalid-cast","title":"InvalidCast","status":500,"detail":"Invalid cast from \u0027System.Int32\u0027 to \u0027Cnblogs.Infrastructure.Primitives.PostConfig\u0027.","instance":"/zzkdocuments"} |
from:https://q.cnblogs.com/q/121590/
View Details改单个项目 在项目的build.gradle文件中,修改repositories配置,将mavenCentral()改为 maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}, 如:
1 2 3 |
repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } |
更改所有项目 如果想一次更改所有的仓库地址,可以在 USER_HOME/.gradle/文件夹下添加 init.gradle 文件来配置,如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
allprojects{ repositories { def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/' all { ArtifactRepository repo -> if(repo instanceof MavenArtifactRepository){ def url = repo.url.toString() if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) { remove repo } } } maven { url REPOSITORY_URL } } } |
作者:xiaolyuh 链接:https://www.jianshu.com/p/471227b2b7e8 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
View Details