I'm writing an ASP.NET Core app, and I'm trying to use a file's path without exposing it to the web. I set it to copy to output directory, so it loads when I test it on localhost, but it gives me an error when published to the web:
The system cannot find the file specified.
This is the code that generates the path:
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "filename.p12");
I've also tried
Path.Combine(Environment.CurrentDirectory, "Config", "filename.p12");
I'm guessing AppDomain.CurrentDomain.BaseDirectory
and Environment.CurrentDirectory
point to a different location when published? Or filename.p12
's 'Copy to Output Directory' property doesn't carry over to the published version?
EDIT:
I also tried:
Path.Combine(environment.ContentRootPath, "Config", "file.p12");
Where environment
is an IHostEnvironment
, to the same effect. I'm getting the feeling that the file isn't being copied over into the published version. So, I changed the filename I put in this question to be file.p12
instead of file.txt
, which is what I originally put it as, in case it doesn't copy over that type of file for security reasons.