AppSettings in App or Web Config Using a Linked File

前端 未结 3 1399
独厮守ぢ
独厮守ぢ 2021-01-11 11:48

I\'m trying to reference some common config settings between a Windows Service and an ASP.NET MVC website. I am doing this by using the file attribute on appSettings in eit

相关标签:
3条回答
  • 2021-01-11 11:55

    I use this to access another .exe's config file, not sure whether it will work with a MVC project, but this might get you closer:

    string proj2Exe = @"C:\projects\proj2\bin\Debug\proj2.exe";
    Configuration proj2Config = ConfigurationManager.OpenExeConfiguration(proj2Exe);
    string mysetting = proj2Config .AppSettings.Settings["ThatSetting"].Value;
    
    0 讨论(0)
  • 2021-01-11 12:04

    The idea of using "bin/..." is good but leads to an error saying that "/" is an invalid character in the resulting virtual path.

    The proper solution is tu use "bin...".

    Cheers

    0 讨论(0)
  • 2021-01-11 12:06

    In the Web.Config you must add "bin/" (se example below).

    By default the web.config is NOT copied into the bin folder but the file common.config is, therefore you must add the path from web.config. In a non-web project the default behavior is that the App.config is copied to the bin folder with name MyProgram.exe.config and is in the same directory as common.config.

    <appSettings file="bin/common.config">
    
    0 讨论(0)
提交回复
热议问题