我如何制作.dnn清单文件以在web.config中为我的孩子创建父节点,而不是如果父节点不存在?
我正在开发DNN模块。我需要通过.dnn清单文件编辑Web.config。我需要为URL重写添加规则。我需要它看起来像这样:
<rewrite>
<rules>
<rule name="rule1">
{some content here}
</rule>
<rule name="rule2">
{some content here}
</rule>
</rules>
</rewrite>
因此,主要目标实际上是在安装时添加1个规则,并在模块删除上删除它。这是我首先尝试过的.dnn文件中的代码:
<component type="Config">
<config>
<configFile>web.config</configFile>
<install>
<configuration>
<nodes>
<!--<node path="/configuration/system.webServer" action="add" collision="overwrite">
<rewrite>
<rules>
</rules>
</rewrite>
</node>-->
<node path="/configuration/system.webServer/rewrite/rules" action="add" collision="overwrite">
<rule name="rule1">
{some content here}
</rule>
</node>
</nodes>
</configuration>
</install>
<uninstall>
<configuration>
<nodes>
<node path="/configuration/system.webServer/rewrite/rules/rule[@name='rule1']" action="remove">
</node>
</nodes>
</configuration>
</uninstall>
</config>
</component>
问题是,如果节点“重写”和“规则”不存在,则不会创建它们,并且在安装中根本没有发生任何事情。
因此,我尝试添加上面评论的代码,以使用collision =“ imprision =“ nighore”
创建节点“重写”和“规则”,以避免重复。但是它无法正常工作。如果存在“重写/规则”并且已经包含一些规则 - 那么DNN认为这些节点是不同的,因为现有的节点包含子女,而需要创建的节点没有孩子。并创建了重复的“重写”。这样:
<rewrite>
<rules>
<rule name="rule_existing_before_module_install">
{some content here}
</rule>
<rule name="rule_added_on_module_install">
{some content here}
</rule>
</rules>
</rewrite>
<rewrite> <!--duplicated nod created by uncommented code-->
<rules>
</rules>
</rewrite>
如果我尝试通过将我的规则包裹在“重写”和“规则”中,将我的规则包裹起来,那么它不与现有的“重写”合并,而是创建第二个节点,而是与Web.config这样最终创建第二个节点:
<rewrite>
<rules>
<rule name="rule1">
{some content here}
</rule>
</rules>
</rewrite>
<rewrite>
<rules>
<rule name="rule2">
{some content here}
</rule>
</rules>
</rewrite>
因此,最终,如果只有在不存在的情况下才有一种方法可以创建“重写/规则”节点,并且使其同时适用于有或没有孩子的节点,或者使我的“重写/规则/规则”与现有一个合并 - 将解决问题。 尝试使用Google - 没有发现对这种情况有帮助的东西。 使用我的现有规则覆盖现有规则并删除现有规则不是一个选择。 目前,我正在考虑手动“重写/规则”的创建,其余要留给模块的.DNN清单文件,但这不是最好的选择。
有什么建议吗?
PS我尝试添加现有标签“ DNN模块”,但出于某种原因,编辑器在标签搜索中找不到它。也许是一个错误,因为它存在,但到目前为止没有问题?
I'm working on a DNN module. I need to edit web.config via .dnn manifest file. I need to add rule for url rewrite. I need it to look like this:
<rewrite>
<rules>
<rule name="rule1">
{some content here}
</rule>
<rule name="rule2">
{some content here}
</rule>
</rules>
</rewrite>
So main goal is actually to add 1 rule on install and delete it on module deletion. Here is the code from .dnn file that I tried first:
<component type="Config">
<config>
<configFile>web.config</configFile>
<install>
<configuration>
<nodes>
<!--<node path="/configuration/system.webServer" action="add" collision="overwrite">
<rewrite>
<rules>
</rules>
</rewrite>
</node>-->
<node path="/configuration/system.webServer/rewrite/rules" action="add" collision="overwrite">
<rule name="rule1">
{some content here}
</rule>
</node>
</nodes>
</configuration>
</install>
<uninstall>
<configuration>
<nodes>
<node path="/configuration/system.webServer/rewrite/rules/rule[@name='rule1']" action="remove">
</node>
</nodes>
</configuration>
</uninstall>
</config>
</component>
Problem is that if nodes "rewrite" and "rules" don't exist they are not created and nothing is happening at all on install.
So I tried to add the code that is commented above to create node "rewrite" and "rules" inside of it with collision="ignore"
to avoid duplicates. But it doesn't work properly. If "rewrite/rules" exists and it contains already some rules - then DNN thinks that those nodes are different because the existing one contains children and the one that needs to be created has no children. And duplicated "rewrite" is created. Like this:
<rewrite>
<rules>
<rule name="rule_existing_before_module_install">
{some content here}
</rule>
<rule name="rule_added_on_module_install">
{some content here}
</rule>
</rules>
</rewrite>
<rewrite> <!--duplicated nod created by uncommented code-->
<rules>
</rules>
</rewrite>
If I try to add all the nodes at once by wrapping my rule inside "rewrite" and "rules" then it's not merged with existing "rewrite" but instead creates second one and I end up with web.config like this:
<rewrite>
<rules>
<rule name="rule1">
{some content here}
</rule>
</rules>
</rewrite>
<rewrite>
<rules>
<rule name="rule2">
{some content here}
</rule>
</rules>
</rewrite>
So eventually if there was a way to create "rewrite/rules" nodes on condition only if they don't exist and make it work both for node with and without children or make my "rewrite/rules" to merge with existing one - it would solve the problem.
Tried to google - didn't find anything helpful for this case.
Overwriting existing rules with mine and deleting existing rules is not an option.
Currently I'm thinking of manual "rewrite/rules" creation and the rest to leave for module's .dnn manifest file but it's not the best option.
Any suggestions?
P.S. I tried to add existing tag "dnn-module" but editor doesn't find it in tag search for some reason. Maybe a bug because it exists but has no questions so far?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这种情况确实是目标的目标,因为并非所有安装实际上都会支持本节。 (重写是一项可选的IIS功能,添加本节而无需启用的IT启用将使站点降低),
因此,当前的配置合并功能不支持此确切的途径,因为您实际上可能会引入新功能/破坏变化,因此它仅适用于现有的那些部分。
如果您觉得必须这样做,则可以使用 iupgradable 这是,但是请再次意识到是否有建立公众消费的风险,可能会对网站造成真正的伤害。
I don't believe that this scenario, is really the targeted goal, as not all installations will actually support this section. (Rewrites is an optional IIS feature, adding this section without it enabled will take a site down)
As such, the current configuration merge functionality doesn't support this exact pathway as you are actually potentially introducing new features/breaking changes so the behavior that it only works with those sections existing is expected.
If you feel that you MUST do this, you could use IUpgradable to have your own custom code modify this, but again, be aware if building for public consumption you run the risk of doing real harm to a site.