我创建的web.config文件自定义栏目,但它无法加载是要管理一节我的自定义类型。
下面是定义:
<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; }
}
}
}
}
我得到一个运行时异常,上面写着:
发生错误创建MembershipProviders配置节处理程序:无法加载类型“MyApp.BusinessObjects.MembershipProviderFactory.MembershipProvidersSection”。
更新
我也包含在配置文件中的实际部分,如下所示:
<MembershipProviders currentProvider ="DefaultMembershipProvider" />
我仍然得到同样的异常。