最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How can I load a content file from a child project in an ASP.NET application - Stack Overflow

programmeradmin0浏览0评论

I have an ASP.NET (.NET 4.7) application and I want to load a static file that's included in my project.

The problem is the project is a child of the main web project. I can't find a way of actually finding the right path. The file is marked as content and copy to output directory and I can see it in the bin folder of the parent project.

This child project doesn't reference any MVC stuff so I don't have access to HttpContext.

My failed attempts so far:

  • Assembly.GetExecutingAssembly().Location - returns Temp folder that only contains dll / pdb files for my child project (and a random .ini file)
  • AppDomain.CurrentDomain.BaseDirectory - returns the root of the parent project's folder (not the bin, but the location of the .csproj)
  • Environment.CurrentDirectory - returns the IIS Express folder
  • The path "." references the IIS Express folder

This seems such a basic thing - I must be missing something obvious!

发布评论

评论列表(0)

  1. 暂无评论