Tag: 配置

代码Behing更新web.config映射问题

我从后面的代码我需要更新我的web.config。 这在以前从来就不是问题,但是我最近收到了一个错误。 错误说“无法映射路径’/’。” 注释掉的线条是我尝试的不同变化。 //Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(Server.MapPath(“~”)); //Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(“~”); //Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(null); Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(“.”); // update pages theme RoleManagerSection section = (RoleManagerSection)myWebConfig.GetSection(“system.web/roleManager”); section.DefaultProvider = “SqlRoleManager”; section.Providers.Clear(); ProviderSettings providerSettings = new ProviderSettings(); providerSettings.Name = “SqlRoleManager”; providerSettings.Type = “System.Web.Security.SqlRoleProvider”; providerSettings.Parameters.Clear(); providerSettings.Parameters.Add(“connectionStringName”, “SimpleTickConnection”); providerSettings.Parameters.Add(“applicationName”, “TheaterSales”); section.Providers.Add(providerSettings); myWebConfig.Save();

我什么时候需要管理托管资源?

我一直在看标准的Dispose模式,我只是想知道我需要写什么来免费管理资源? 如果这些资源已经“管理”,那么我肯定不需要做任何事情。 如果是这种情况,并且我的类没有任何非托管资源(因此不需要GC最终确定)那么我只需要在Dispose方法中抑制终结吗? : – public void Dispose() { GC.SuppressFinalize(this); } 所以假设这是我的class级: public sealed class MyClass : IDisposable { IList objects; // MyObject doesn’t hold any unmanaged resource private bool _disposed; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (!_disposed) { // do I need to set the list to […]

如何包装和替换ASP.NET 5配置中的一个默认组件

ASP.NET 5(RC1)为我们提供了一个全新的配置模型,我们将配置添加/替换为ServiceDescriptor对象的集合。 替换默认实现很简单,例如: services.Add(ServiceDescriptor.Instance( new MyHttpContextAccessor())); 但是,我很难找到一种方法来扩展现有注册的额外行为(通过装饰)。 换句话说,我想用内部使用内置版本的自定义版本替换内置版本。 以这种方式扩展框架行为当然很常见。 例如: // How to get the instance here??? IHttpContextAccessor original = services.Last(service => service.ServiceType == typeof(IHttpContextAccessor)); services.Add(ServiceDescriptor.Instance( new HttpContextAccessorDecorator(original))); 请注意,使用IHttpContextAccessor只是一个示例,但确实有效地显示了问题。 services集合包含ServiceDescriptor对象,对于IHttpContextAccessor , ImplementationInstance和IHttpContextAccessor属性为空,从而无法获取该原始实例。 我们不能将一个IServiceProvider注入装饰器来延迟注册,因为一旦我们在装饰器中请求一个IHttpContextAccessor ,我们就会得到相同的装饰器,这将导致一个stackoverflowexception。 有趣的是,使用MVC 5和Web API,这实际上非常简单。 如何在ASP.NET 5中实现相同的function?

将web.config部分读取到List

我在web.config中有这个: 我想读取所有部分“MySection”并获取List所有值(例如:“10”,“20”,“30”) 谢谢,

App.Config自定义配置部分问题

我为我的应用程序创建了一个自定义配置部分。 由于某些原因,Visual Studio 2010没有拾取和我的自定义属性。 对于所有“添加”键,我收到与此类似的警告: Could not find schema information for the element ‘urlFilterSection’ 配置文件: UrlFilterSection: namespace BotFinderApp.Models { public class UrlFilterSection : ConfigurationSection { public UrlFilterSection() { } [ConfigurationProperty(“urlFilterCollection”, IsDefaultCollection = false)] [ConfigurationCollection(typeof(UrlFilterCollection), AddItemName = “add”, ClearItemsName = “clear”, RemoveItemName = “remove”)] public UrlFilterCollection Urls { get { var urlsCollection = (UrlFilterCollection)base[“urlFilterCollection”]; return urlsCollection; […]

WPF – AvalonDock – 结算文件

我在WPF项目中使用AvalonDock和MVVM。 当我点击“X”(选项卡的关闭按钮)时,我的文档关闭但保留在内存中。 它似乎只是隐藏了。 它不会从我的Model.Documents集合中删除。 如果我添加DockingManager_DocumentClosing并尝试从集合中删除我的文档,我会在Xceed.Wpf.AvalonDock.Layout.LayoutContent的以下方法中收到Exception,因为parentAsContainer为null。 /// /// Close the content /// /// Please note that usually the anchorable is only hidden (not closed). By default when user click the X button it only hides the content. public void Close() { var root = Root; var parentAsContainer = Parent as ILayoutContainer; parentAsContainer.RemoveChild(this); if (root != null) […]

UserControl中的ConfigurationManager连接字符串为null

我有一个应用程序通过数据层获取数据到表单,使用这样的东西: public DataTable get(String query, ArrayList parameters = null) { using (iDB2Connection cn = new iDB2Connection(ConfigurationManager.ConnectionStrings[“iseries”].ToString())) { // get the data and return them } } 我有获取数据的表单,这很好用。 但是,我创建了一个UserControl,它通过这个方法获取数据,当我运行我的项目时工作正常,但是,包含UserControl的表单会引发设计器exception。 “为了防止在加载设计器之前丢失数据,必须解决以下错误:” 我发现错误位于从检索连接字符串时。 它会抛出nullpointerexception。 但仅限于设计模式。 当我忽略它时,一切正常,但是,我想知道如何解决这个问题。 通过我的UserControl访问它们时,为什么我的 null? 更新1 似乎我的UserControl根本无法识别 。 当我将此代码放入UserControl Load事件时,我也得到了一个null引用。 private void SelectUser_Load(object sender, EventArgs e) { txtLocation.Text = ConfigurationManager.AppSettings[“location”].ToString(); }

OledbConnection.Dispose()是否关闭连接?

可能重复: 如果使用using子句,是否需要关闭DbConnection? OledbConnection.Dispose()是否关闭连接? 我知道SqlConnection做但是OledbConnection呢?

不可变类型作为配置属性

是否可以将不可变类型用作.NET配置API的配置属性? 假设我有一个名为MyClass的不可变类型: public class ImmutableClass { private readonly int value; public ImmutableClass(int value) { this.value = value; } public int Value { get { return this.value; } } } 我想在ConfigurationSection中使用此类型作为配置属性: public class MyConfigurationSection : ConfigurationSection { [ConfigurationProperty(“foo”)] public ImmutableClass Foo { get { return (ImmutableClass)base[“foo”]; } set { base[“foo”] = value; } } } 当我这样做时,我无法序列化和反序列化MyConfigurationSection,因为它会抛出此exception: […]

app.config中的自由格式XML配置部分正文

有没有办法建立一个允许自由forms的XML体的配置部分? 我如何在代码中获得自由forms的主体? 例如,我想像这样创建一个ModuleConfigurationSection: http://myserver/myservice.svc c:\directory 因此,一些代码会使用ConfigurationManager.GetSection(“modules”)从配置节中调出每个模块类型,并且我想将moduleConfig元素中的XML作为opaque配置值传递给模块类的构造函数。 任何输入赞赏!