I have shared appsettings
in SharedSettings
folder.
I am deploying all the asp.net core application in sub directory.
For development, I have created as site with the following directory
c://Website
Here I am keeping my sharedsettings
.
But I am developing application from another folder. Here I have configured my application to run as sub application in the web sites. Folder could be c://Applications/App1
I want to include the sharedsettings.json in my application. So I have tried the following approach.
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
var sharedFolder = Path.Combine(env.ContentRootPath, "..", "Shared");
config
.AddJsonFile(Path.Combine(sharedFolder, "SharedSettings.json"), optional: true) // When running using dotnet run
.AddJsonFile("SharedSettings.json", optional: true) // When app is published
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
config.AddEnvironmentVariables();
})
But whenever I have tried to get the hosted url path, It always current application hosted directory. (I understand the reason for the result).
But I don't know how to get the root directory path where it is pointing to the different location.