当前位置:网站首页>.Net Core 技巧小结
.Net Core 技巧小结
2022-08-09 14:53:00 【iZaix】
.Net Core 技巧小结
我们写好的.net core 网站想要发布运行,通常会使用IIS或者Windows服务托管,当我们引用的资源特殊,需要单独添加的时候,该怎么做呢?比如说页面加载.glb文件
IIS中MIME配置
当我们使用IIS的方式部署网站,可以打开IIS找到MIME类型
其中有常用的数据类型,如有需求可以点击添加

这样就可以正常的加载特殊格式的文件了。
Kestral中MIME配置
但是在IIS中存在回收机制,对于定时任务,如果长时间没有操作,将会自动回收,定时任务就自动清理掉了,这样就要使用Windows服务的部署方式了,那么在kestral中该如何设置呢,加上如下代码即可。
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".glb"] = "model/gltf-binary";
跨域访问
app.UseCors(options =>
{
options.WithOrigins("http://0.0.0.0"); // 允许特定ip跨域
options.AllowAnyHeader();
options.AllowAnyMethod();
options.AllowCredentials();
});
获取应用路径
程序中往往会出现要读取配置文件的需求,然而,有时在开发环境中测试好的程序,部署了之后就出问题了,提示路径下不存在文件,其实,.net core默认的位置是C盘WINDOWS文件夹中,以下列举集中常用的获取应用程序路径的方法。
// 获取程序的基目录。
var path = AppDomain.CurrentDomain.BaseDirectory;
_logger.Info(path);
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
path = Environment.CurrentDirectory;
_logger.Info(path);
// 获取应用程序的当前工作目录,注意工作目录是可以改变的,而不限定在程序所在目录。
path = Directory.GetCurrentDirectory();
_logger.Info(path);
// 获取和设置包括该应用程序的目录的名称。
path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
_logger.Info(path);
得到结果如下:

边栏推荐
- strlen(), strcpy(), strncpy(), strcat(), strncat(), strcmp(), strncmp()函数的封装
- 浅谈ArraryList的浅克隆和深克隆
- bin文档读写
- How to List < Map> grouping numerical merge sort
- 经典面试题 之 TCP 三次握手/ 四次挥手
- 简单记录下offsetof和container_of
- 启动报错:Caused by: org.apache.ibatis.binding.BindingException汇总解决
- 是什么推动了量化交易接口的发展?
- For programming trading, focusing on forecast or on countermeasures?
- 6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!
猜你喜欢

Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution

数据库多表链接查询的方式

xshell7连接工具下载

DSPE-PEG-Aldehyde, DSPE-PEG-CHO, Phospholipid-PEG-Aldehyde MW: 1000

SNR 信噪比

【小白必看】初始C语言(上)

Mathematica 数据分析(简明)

经典面试题 之 TCP 三次握手/ 四次挥手

浅析Servlet三大容器的常用方法及其作用域

Database multi-table link query method
随机推荐
什么是模板引擎?常见的模板引擎有哪些?thymeleaf的常用指令介绍。
What do professional quantitative traders think about quantitative trading?
MySql中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
排序方法(希尔、快速、堆)
英语议论文读写01 Business and Economics
Play in the cloud | The ever-changing gameplay of Tianyi cloud computer
[Mysql]--事务、事务的隔离级别、脏读、不可重复读、幻读解析
PAT1027 打印沙漏
物理学专业英语(词汇整理)--------07
How do users correctly understand programmatic trading?
运算符学习
内存泄露检测工具VLD(Visual Leak Detector)使用说明
My MySQL database was attacked and deleted for ransom, forcing me to use all my might to recover data
二叉排序树的左旋与右旋
分析:通过哪种方法来建立股票量化交易数据库?
[MySql]实现多表查询-一对一,一对多
在服务器上远程使用tensorboard
Stock trading stylized how to understand their own trading system?
[ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
Seize the opportunity of quantitative trading fund products, and quantitative investment has room for development?