从code C#更改URL重写规则中的Web.Config [英] Change URL Rewrite Rule in Web.Config from Code C#

查看:468
本文介绍了从code C#更改URL重写规则中的Web.Config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改从C#code重写规则。 URL重写规则是驻留在web.config文件。

I want to modify rewrite rule from C# code. Url Rewrite rule is resides in web.config file.

<system.webServer>
    <rewrite>
      <rules>
        <rule name="partners">
          <match url="^partners$" />
          <action type="Rewrite"
                  url="partners.aspx" />
        </rule>
        <rule name="news">
          <match url="^news$" />
          <action type="Rewrite"
                  url="news.aspx" />
        </rule>
        <rule name="projects">
          <match url="^projects$" />
          <action type="Rewrite"
                  url="projects.aspx" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

我想改变为前。 &LT;规则名称=合作伙伴&GT; &LT;匹配URL =^ $合作伙伴/&GT; &LT;规则名称=合作伙伴&GT; &LT;匹配URL =^友谊/合作伙伴$/&GT;

我怎么能找到节点规则和更新匹配的网址为新的,其中name =合作伙伴;

how can I find node rule and update match url to "new one" where name = "partners";?

这是我的动态URL重写的想法。感谢您的任何其他方式,如果你有。

this is my idea for dynamic url rewriting. thanks for any other ways if you have.

推荐答案

微软有可用来帮助你Microsoft.Web.Administration.dll,但它需要管理员权限来执行,

Microsoft has Microsoft.Web.Administration.dll available to help you out, but it requires administrator permissions to execute,

https://www.iis.net/learn/manage/scripting/how-to-use-microsoftwebadministration

有相当适合WinForms应用程序(如IIS管理)来控制IIS服务器,但也可以在其他类型的应用中使用。

It is quite suitable for a WinForms application (such as IIS Manager) to control an IIS server, but can also be used in other types of applications.

我有一个个人项目,该项目是一个自定义MWA实现,对于一些非管理员情况下工作。如果你有兴趣的话,让我知道。

I do have a personal project that is a custom MWA implementation that works for some non-administrator cases. If you are interested in it, let me know.

这篇关于从code C#更改URL重写规则中的Web.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆