1

我在我的应用程序中应用了 URL 重写,并在 web.config 中定义了一些规则为

  <modulesSection>
        <rewriteModule>
            <rewriteOn>true</rewriteOn>
            <rewriteRules>              
                <rule source="About/About-test" destination="About/About.aspx"/>
                <rule source="test-In-Media" destination="Others/MediaUpdates.aspx"/>
                <rule source="Home" destination="MasterPage/HomePage.aspx"/>                
            </rewriteRules>
        </rewriteModule>
</modulesSection>

<httpModules>
            <add name="RewriteModule" type="RewriteModule.RewriteModule, RewriteModule"/>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>

好的,我找到了我的解决方案..我使用了以下代码片段..

 RewriteModuleSectionHandler cfg =(RewriteModuleSectionHandler)ConfigurationManager.GetSection("modulesSection/rewriteModule");

            if (!cfg.RewriteOn) return;
            string path = HttpContext.Current.Request.Path;

            if (path.Length == 0) return;


            XmlNode xmlNode = cfg.XmlSection.SelectSingleNode("rewriteRules");


            if( xmlNode != null )
            {

            }

现在如何以格式添加新规则???

4

1 回答 1

0

您能否更具体地说明您要添加或修改哪种类型的规则?

要通过应用程序更改 web .config,请阅读以下文章。

http://www.dotnetcurry.com/ShowArticle.aspx?ID=102

于 2013-08-16T12:03:54.053 回答