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>
I want to change for ex. <rule name="partners"> <match url="^partners$" />
to <rule name="partners"> <match url="^friendship/partners$" />
,
how can I find node rule and update match url to "new one" where name = "partners";?
this is my idea for dynamic url rewriting. thanks for any other ways if you have.
I change value for connectionString in my web.config website with this code :
May be this example can help you (just change the value connectionString
by system.webServer
and add
by rules
etc..
Please tell me if it works for you
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load("../myPath/web.config");
foreach (XmlNode node in myXmlDocument["configuration"]["connectionStrings"])
{
if (node.Name == "add")
{
if (node.Attributes.GetNamedItem("name").Value == "SCI2ConnectionString")
{
node.Attributes.GetNamedItem("connectionString").Value = "new value";
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With