Linux下发布.Net Core项目遇到验证码失效怎么办?

摘要:.net Core 部署到在 CentOS7下后,验证码打不开,报The type initializer for 'Gdip' threw an exception.异常 运行含图片处理时发
.net Core 部署到在 CentOS7下后,验证码打不开,报The type initializer for 'Gdip' threw an exception.异常 运行含图片处理时发生异常: The type initializer for 'Gdip' threw an exception. 问题分析: 验证码一般我们是通过System.Drawing.Common 组件提供对GDI+图形功能的访问来实现。它是依赖于GDI+的,在windows平台下没有任何问题,本身就已经支持,Linux上没有GDI+,那么在Linux上如何使用GDI+呢?Mono 团队使用C语言实现了GDI+接口,提供对非Windows系统的GDI+接口访问能力(实质就是模拟GDI+,与系统图像接口对接),这个就是 libgdiplus。 解决办法: 一、安装一下包: yum -y install autoconf automake libtool yum -y install freetype-devel fontconfig libXft-devel yum -y install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel yum -y install glib2-devel cairo-devel yum -y install mlocate git clone https://github.com/mono/libgdiplus cd libgdiplus ./autogen.sh make make install 1、yum -y install autoconf automake libtool 2、yum -y install freetype-devel fontconfig libXft-devel 3、yum -y install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel 4、yum -y install glib2-devel cairo-devel 5、yum -y install mlocate 6、git clone https://github.com/mono/libgdiplus 7、cd libgdiplus 8、./autogen.sh 9、make 10、make install 二、创建符号链接: ln -s /usr/local/lib/libgdiplus.so /usr/lib64/libgdiplus.so ln -s /usr/local/lib/libgdiplus.so /usr/libgdiplus.so 三、更新一下库: updatedb 四、重新启动.NET Core应用 五、重新登录,即可看到验证码了。 六、登录成功