.net6 webapi 项目注册为windows 服务后访问静态文件

直接使用kestrel 运行程序时,只需要 http://localhost:port/file.html 即可访问,但是将程序注册为windows 服务后, http://localhost:port/file.html 会报404的错误,此时要访问到这个文件,http://localhost:port/wwwroot/file.html 才行,如果想要windows服务和web 的url一致 只需要加入以下配置即可解决这个问题。

//appsettings.json
{
  "StaticFile": {
    "ServeEnabled": true,
    "ServeFromSubFolder": false
  }
}
posted @ 2023-10-08 11:13  呱呱蛙ꪝ·  阅读(272)  评论(1)    收藏  举报