In the FeatureActivated event (WebApplication scope) I want to read the web.config file to get the connection string from there. I use the following code to open web.config:
Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);
Everything works fine when I activate the function through the web interface, but when I try to do the same with PowerShell (Enable-SPFeature), the code crashes. From what I saw, the code opens an invalid web.config file from the path C: \ inetpub \ wwwroot \ web.config (which does not exist) instead of C: \ inetpub \ wwwroot \ wss \ VirtualDirectories \\ web.config.
Can someone give me a workaround for this problem?
source share