這裏是我的XML結構:是否可以進行此自定義配置?
<reco>
<styleSheets>
<group>
<asset source="~/Script/file1.css"/>
<asset source="~/Script/file2.css"/>
<asset source="~/Script/file3.css"/>
</group>
</styleSheets>
<scripts>
<group>
<asset source="~/Content/file1.js"/>
<asset source="~/Content/file1.js"/>
<asset source="~/Content/file1.js"/>
</group>
</scripts>
這裏是我的代碼:
public class AssetConfigurationElement : ConfigurationElement
{
/// <summary>
/// Gets or sets the source.
/// </summary>
/// <value>The source.</value>
[ConfigurationProperty("source", IsRequired = true, IsKey = true)]
public string Source
{
get
{
return (string)this["source"];
}
set
{
this["source"] = value;
}
}
}
public class GroupConfigurationElementCollection : ConfigurationElementCollection
{
public GroupConfigurationElementCollection()
{
AddElementName = "asset";
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ConfigurationProperty("name", IsRequired = true, IsKey = true, IsDefaultCollection = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is enabled.
/// </summary>
/// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
[ConfigurationProperty("enabled", DefaultValue = true)]
public bool Enabled
{
get
{
return (bool)this["enabled"];
}
set
{
this["enabled"] = value;
}
}
/// <summary>
/// Gets or sets the version.
/// </summary>
/// <value>The version.</value>
[ConfigurationProperty("version")]
public string Version
{
get
{
return (string)this["version"];
}
set
{
this["version"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is compress.
/// </summary>
/// <value><c>true</c> if compress; otherwise, <c>false</c>.</value>
[ConfigurationProperty("compress", DefaultValue = true)]
public bool Compress
{
get
{
return (bool)this["compress"];
}
set
{
this["compress"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is combined.
/// </summary>
/// <value><c>true</c> if combined; otherwise, <c>false</c>.</value>
[ConfigurationProperty("combined", DefaultValue = true)]
public bool Combined
{
get
{
return (bool)this["combined"];
}
set
{
this["combined"] = value;
}
}
protected override ConfigurationElement CreateNewElement()
{
return new AssetConfigurationElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((AssetConfigurationElement)element).Source;
}
}
public class SharedGroupConfigurationSection : ConfigurationSection
{
/// <summary>
/// Gets the style sheets.
/// </summary>
/// <value>The style sheets.</value>
[ConfigurationProperty("styleSheets")]
[ConfigurationCollection(typeof(GroupConfigurationElementCollection), AddItemName = "group")]
public GroupConfigurationElementCollection StyleSheets
{
get
{
return (GroupConfigurationElementCollection)base["styleSheets"] ?? new GroupConfigurationElementCollection();
}
}
/// <summary>
/// Gets the style sheets.
/// </summary>
/// <value>The style sheets.</value>
[ConfigurationProperty("scripts")]
[ConfigurationCollection(typeof(GroupConfigurationElementCollection), AddItemName = "group")]
public GroupConfigurationElementCollection Scripts
{
get
{
return (GroupConfigurationElementCollection)base["scripts"] ?? new GroupConfigurationElementCollection();
}
}
}
這是配置甚至可能嗎?如果是這樣,我做錯了什麼?
當我嘗試使用配置管理器獲取該段時,出現此錯誤消息。
Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized element 'asset'.
Source Error:
Line 96: Line 97: Line 98: Line 99: Line 100:
Source File: D:\ASP.NET Projects\Resource-Compiler\ResourceCompiler\Examples\web.config Line: 98
,你應該看到和使用** [盒帶(http://getcassette.net/)**,而不是做從頭開始......再加上,它支持更多。試試看! – balexandre