Reputation: 403
I have a .Net Core project. As part of my database Context class I have some seed data to insert into the database. This seed data is deserialized from a seed.json file in the root directory and holds paths to images in it. These images are in a folder in the project. Before inserting the data I get these images, upload them to Azure cloud storage, and change the paths to point to there. This works great locally.
So now I publish my app to Azure App Service and a FileNotFound exception appears. It can no longer find the images in the project. Looking at the filesystem on Azure's Kudu dashboard I don't see my project folders but instead a bunch of .dll and .pdb files. I can only speculate that Azure maybe bundles the folders into .dll's?
I can still access the wwwroot/images just fine but would prefer not to for securitys sake.
What can I do to publish my folder to their filesystem or get access to my files on their filesystem?
Upvotes: 1
Views: 1641
Reputation: 507
You might need to set your project working directory in Program.cs. You can then access your files relative to the .dll directory.
var currentDir = Directory.GetCurrentDirectory();
config.SetBasePath(currentDir)
And possibly need to copy across the seed.json and images folder to the output of the project:
`<Content Include="seed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="images/**/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
`
Hope it helps Dave
Upvotes: 2