jjzjj

appsetting

全部标签

c# - 依赖注入(inject)和 AppSettings

假设我正在为我的应用程序定义一个浏览器实现类:classInternetExplorerBrowser:IBrowser{privatereadonlystringexecutablePath=@"C:\ProgramFiles\...\...\ie.exe";...codethatusesexecutablePath}乍一看这似乎是个好主意,因为executablePath数据靠近将使用它的代码。当我尝试在另一台具有外语操作系统的计算机上运行相同的应用程序时,问题就来了:executablePath将具有不同的值。我可以通过AppSettings单例类(或其等效类之一)解决此问题,但

c# - 为什么在运行时没有考虑我在 App.config 中对 AppSettings 的更改? (控制台应用程序)

我有一个控制台应用程序,它有自己的App.config。我需要不时更改部分中的一些值。我的问题是,当我在bin/debug文件夹中执行exe时,它​​会正确获取相关的应用程序设置。但是当我编辑和更改一些键/值对的值并重新运行exe时,它​​仍然读取原始值。(我所说的重新运行是指通过调用MyTool.exe在命令提示符下运行应用程序)我试着打电话ConfigurationManager.RefreshSection("appSettings");在我的Main方法的开头。但没有帮助。你能给点建议吗?谢谢 最佳答案 ButwhenIed

c# - .net 配置文件 AppSettings : NameValueCollection vs. KeyValueConfigurationCollection

访问当前应用程序的appSettings时,我得到一个NameValueCollection:NameValueCollectionsettings=ConfigurationManager.AppSettings;当访问另一个应用程序的appSettings时,我得到一个KeyValueConfigurationCollection:KeyValueConfigurationCollectionsettings=ConfigurationManager.OpenExeConfiguration(sExe).AppSettings.Settings;这两个方法(Configuratio

c# - ConfigurationManager.AppSettings 返回 null

我正在使用ConfigurationManager.AppSettings[myKey]从我的Windows应用程序中的app.config文件中读取一个值,但返回的值始终为null,即使键存在并且它有一个值,Deas任何人都知道为什么?谢谢 最佳答案 一个可能更简单的替代方法是使用设置文件。这将App.config值的创建和维护封装在设计器GUI中,并生成用于访问这些值的代码。要添加设置文件,请在VS中右键单击您的项目并单击“添加->新项”,选择“设置文件”并为其指定一个有意义的名称,例如MainSettings.settings

c# - 使用链接文件的 App 或 Web Config 中的 AppSettings

我正在尝试引用Windows服务和ASP.NETMVC网站之间的一些常见配置设置。我通过在App.config或Web.config(分别)中使用appSettings上的文件属性来执行此操作。被引用的文件(名为common.config)是同一解决方案中单独项目中的链接文件。在两个项目中,common.config设置为Content和CopyAlways。Thisstackanswertoasimiliarquestion似乎建议至少对于configSource这个解决方案是可行的。我不想要configSource,因为我只希望两个项目中的一些属性是通用的。更新:我刚刚试过了,co

c# - 使用从 appsettings.json 到 startup.cs 的连接字符串

目前在启动中,我的sqlserver字符串如下所示:publicvoidConfigureServices(IServiceCollectionservices){varconnection=@"Server=servername;Database=database;Trusted_Connection=True;MultipleActiveResultSets=true";services.AddDbContext(options=>options.UseSqlServer(connection));}如何使用我的appsettings.json中的内容:{"Data":{"Defa

c# - 从 .NET Core 2 中的类读取 appsettings.json

我需要从业务类中的appsettings.json文件(部分:placeto)读取属性列表,但我无法访问它们.我需要公开这些属性。我将文件添加到Program类中:这是我的appsettings.json:{"Logging":{"IncludeScopes":false,"LogLevel":{"Default":"Warning"}},"placeto":{"login":"fsdfsdfsfddfdfdfdf","trankey":"sdfsdfsdfsdfsdf"}} 最佳答案 首先:使用program.cs中的默认值,因为

c# - WebConfigurationManager.AppSettings 的缓存?

我有很多读取我的Web配置文件的请求variable=WebConfigurationManager.AppSettings["BLAH"]WebConfigurationManager.AppSettings是每次都从磁盘读取,还是缓存在内存中?如果每次都从磁盘读取它,那么我想我需要将该变量移动到静态变量以提高我的应用程序性能。 最佳答案 配置设置缓存在内存中,每次调用此函数时不会解析web.config。 关于c#-WebConfigurationManager.AppSetting

c# - 如何确保将 appsettings.dev.json 复制到输出文件夹?

我有三个配置文件,每个环境一个:appsettings.json->生产appsettings.dev.json->开发appsettings.stg.json->暂存如果我将ASPNETCORE_ENVIRONMENT设置为dev,我会收到一个运行时异常,提示无法找到appsettings.dev.json。我尝试添加"copyToOutput":["appsettings.dev.json"]到project.json中的buildOptions部分,但它似乎没有任何效果。还有其他方法可以强制将appsettings.dev.json复制到输出目录吗?

c# - 访问 Controller 类中的 appsettings.json 值

无法弄清楚如何读取startup.cs之外的appsettings.json值。我想做的是,例如,在_Layout.cshtml中,从配置中添加站点名称:例如:ViewData["SiteName"]=Configuration.GetValue("SiteSettings:SiteName");或者更好:publicclassGlobalVars{publicstaticstringSiteName=>Configuration.GetValue("SiteSettings:SiteName");}到目前为止,这是我的代码:[应用设置.json]"SiteSettings":{"Si