Using a .NET Framework 4.8 as an API application for a website.
//web config
<add key="id" value="123" />
//code inside main project solution, this works
var Id = ConfigurationManager.AppSettings["id"];
//code inside extra class library project, this is NULL
var Id = ConfigurationManager.AppSettings["id"];
We are in the process of publishing to AppServices but i'm having some issues with accesing a variable.
So our project has a web.config file. I know I can set the variables here for local developent then, keeping the same name of each variable add to the Configuration section of the App service and this will override the local, on app service That is fine and working.
Inside our solution we have many extra class libary projects that are part of the solution as a whole, but not part of the actual main project itself.
When accesing one of these class library projects I can't access the variables from the web.config in the original project. (currently the value is set in code, but we want to change it to config settings so we can use it from app service configuration) (I know we could use a keyVault, which would solve the acces problem, but we arn't using this apporach)
I could add the variable to the app.config of the class library project, but then would it get picked up in the app service config settings? I'm assuming this only applies to the web.config file
I have tried many things, I was able to use the hardcoded location of the web.config file (from inside the class library project) to:
var path = @"C:\Users\PathNameOnLocalMachine";
string file = Path.GetFileName(path);
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
string id = config.AppSettings.Settings["id"].Value;
this worked but I can't use this when we go to app service I thought about trying to find the location of the web.config on app service and use that, but google says no.
My question I am getting around to asking is: is there anyway I can set a variable in app settings of the configuration settings in app serivce, and dont have it mentioned in web config file, but I can use it in the class library solution code. (which would return null on local dev) but show the correct value on app service.
I have tried this and it didn't work, still returning null. It appears the var has to be mentioned in both the web.config and config settings on appService.
Are there any other work arounds? Or any ideas please? Thank you for any advice