无法创建web.config文件自定义栏目 [英] Unable to create a custom section for web.config
问题描述
我创建的web.config文件自定义栏目,但它无法加载是要管理一节我的自定义类型。
I created a custom section in the web.config file but it isn't able to load my custom type that is going to manage the section.
下面是定义:
<configSections>
<section
name="MembershipProviders"
type="MyApp.BusinessObjects.MembershipProviderFactory.MembershipProvidersSection"
allowLocation="true"
allowDefinition="Everywhere"
/>
</configSections>
namespace MyApp.BusinessObjects
{
public class MembershipProviderFactory
{
internal virtual IMembershipProvider Create()
{
}
public class MembershipProvidersSection : ConfigurationSection
{
public class AddElement: ConfigurationElement
{
[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("type", IsRequired = true)]
public string FullyQualifiedTypeName
{
get
{
return this["type"].ToString();
}
set
{
this["type"] = value;
}
}
}
public class AddElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new AddElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((AddElement)element).Name;
}
}
[ConfigurationProperty("currentProvider", IsRequired = false)]
public string CurrentProvider
{
get
{
return this["currentProvider"].ToString();
}
set
{
this["currentProvider"] = value;
}
}
[ConfigurationProperty("add", IsRequired = true, IsDefaultCollection = true)]
public AddElementCollection Instances
{
get { return (AddElementCollection)this["add"]; }
set { this["add"] = value; }
}
}
}
}
我得到一个运行时异常,上面写着:
I get a run-time exception that says:
的时出错创建MembershipProviders配置节处理程序:无法加载类型MyApp.BusinessObjects.MembershipProviderFactory。 MembershipProvidersSection。的
更新
我还包括实际在配置文件中部分如下:
I also included the actual section in the config file as follows:
<MembershipProviders currentProvider ="DefaultMembershipProvider" />
我仍然得到同样的异常。
I still get the same exception.
推荐答案
您需要指定组件名称的一部分键入
属性:
You need to specify the assembly name as part of the type
attribute:
<section
name="MembershipProviders"
type="Namespace.TheCustomSection, TheAssemblyNameGoesHere"
allowLocation="true"
allowDefinition="Everywhere"
/>
修改结果
我没注意到在 MembershipProvidersSection
类是一个的嵌套的类结果
类型名称应该是:
EDIT
I didn't notice that the MembershipProvidersSection
class is a nested class.
The type name should be:
MyApp.BusinessObjects.MembershipProviderFactory+MembershipProvidersSection
这篇关于无法创建web.config文件自定义栏目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!