jjzjj

configuration

全部标签

c# - 如何在 .net 4.5 中读取连接字符串

如何从web.config文件读取4.5.net框架中连接字符串的值?我正在使用我引用的system.configuration和using语句,但之后唯一要使用的是.ConfigurationSettings.Appsettings。没有连接字符串设置。 最佳答案 usingSystem.Configuration;stringconnectionString=ConfigurationManager.ConnectionStrings["StringName"].ConnectionString;编辑(添加对System.Con

c# - 为什么使用 ConfigurationManager.GetSection 会导致 "SecurityException: Request failed"但 ConfigurationManager.OpenExeConfiguration 不会?

我有一些好奇,希望.Net专家可以帮助我。我有一个自定义配置部分,为了掌握它,我这样做:vars=(TestConfigurationSection)ConfigurationManager.GetSection("testSection");我在我的开发机器(Windows7,64位,Windows完全最新)上运行它并且运行良好。我将包含该代码的exe文件放入WindowsServer2008R2机器上的c:\users\public目录中,打开一个以管理员身份运行命令提示符,运行它,我得到:System.Configuration.ConfigurationErrorsExcept

c# - 如何以编程方式修改 app.config 中的 assemblyBinding?

我试图通过使用XmlDocument类并直接修改值来在安装时更改bindingRedirect元素。这是我的app.config的样子:......然后我尝试使用以下代码将1.0更改为2.0privatevoidSetRuntimeBinding(stringpath,stringvalue){XmlDocumentxml=newXmlDocument();xml.Load(Path.Combine(path,"MyApp.exe.config"));XmlNoderoot=xml.DocumentElement;if(root==null){return;}XmlNodenode=r

c# - 加载配置文件时如何修复 "Configuration system failed to initialize/Root element is missing"错误?

我在我的C#Windows应用程序中遇到了这个错误:“配置系统初始化失败”。它运行良好。突然我得到了这个异常(exception)。它将内部异常详细信息显示为“缺少根元素”。(C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\TouchStation.vshost.exe_Url_no1nets4fg3oy2p2q2pnwgulbvczlv33\1.1.0.12\user.config)”}。当我尝试从Settings.cs类获取值时会发生这种情况。在program.cs文件中写了下面的代码if(Properties.Se

c# - 在哪里存储简单 .NET 应用程序的配置?

我正在编写一个相当简单的应用程序,我想将其简化为一个简单的EXE文件+一些数据存储(例如XML)。我的问题是关于配置文件的。把那些文件放在哪里?我看到一些应用程序只有一个EXE文件(uTorrent、MediaPlayerClassic-我无需任何安装即可使用它们),但它们将配置存储在其他地方。如何实现?您会如何处理这种情况?是尝试实现我上面描述的事情更好,还是简单地使用配置文件和数据存储在与EXE文件相同的目录中? 最佳答案 在同一文件夹(或App_Data)中创建或使用文件是非常标准的做法。您使用像InnoSetup(免费)这样

c# - .NET Core 使用配置绑定(bind)到带有数组的选项

使用.NETCoreMicrosoft.Extensions.Configuration是否可以将配置绑定(bind)到包含数组的对象?ConfigurationBinder有一个方法BindArray,所以我认为它会起作用。但是当我尝试它时,我得到了一个异常(exception):System.NotSupportedException:ArrayConvertercannotconvertfromSystem.String.这是我精简后的代码:publicclassTest{privateclassExampleOption{publicint[]Array{get;set;}}[

c# - 无效操作异常 : No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme

我正在尝试按照说明进行操作here将Cookie身份验证添加到我的网站。到目前为止,我添加了以下内容:InvoketheUseAuthenticationmethodintheConfiguremethodoftheStartup.csfile:app.UseAuthentication();InvoketheAddAuthenticationandAddCookiemethodsintheConfigureServicesmethodoftheStartup.csfile:services.AddAuthentication("MyCookieAuthenticationScheme

c# - ConfigurationManager 类不可用

我无法从App.Config文件中获取connectionString..我错过了什么吗?创建类(class)后,我将类(class)移到了某个文件夹中。这是问题所在吗?不移动类的解决方案是什么? 最佳答案 添加对System.Configuration.dll的引用。菜单栏->项目->添加引用...->.NET(选项卡)->System.Configuration->确定 关于c#-ConfigurationManager类不可用,我们在StackOverflow上找到一个类似的问题:

C# - 用户设置损坏

我们在读取标准.Net用户设置时发生了一个罕见的异常(这是在VS2008的“项目属性”中找到的):System.Configuration.ConfigurationErrorsExceptionwascaughtMessage="Configurationsystemfailedtoinitialize"Source="System.Configuration"BareMessage="Configurationsystemfailedtoinitialize"Line=0StackTrace:atSystem.Configuration.ConfigurationManager.P

c# - ConfigurationProperty 由于其保护级别而无法访问

我想在程序中读/写(并保存)应用程序的配置文件app.config是这样的:...当我使用ConfigurationManager.GetSection读取app.config时,它起作用了:varadwords_section=(System.Collections.Hashtable)System.Configuration.ConfigurationManager.GetSection("AdWordsApi");Console.WriteLine((string)adwords_section["LogPath"]);但是当我使用ConfigurationManager.Ope