Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • JohnAss 18 posts 128 karma points
    Oct 08, 2020 @ 11:38
    JohnAss
    0

    Edit IISRewriteRules.config programmatically

    I want to make a custom dashboard where I can enable/disable rewrites rules via a checkbox.

    Lets say I have the following rule:

    <rule name="Add trailing slash" stopProcessing="true" enabled="true">
    

    Here I want to finde the rule by its name and be able the change enabled to false.

    I can probably make something work with XmlDocument but I'm curious if someone else has made anything similar. Or if any of you have suggestions as to how to impelment this in a nice clean way.

    Another nice feature would be if the dashboard could registrer if a new rule has been added - and make a checkbox for this rule.

    Any examples / suggest is much appreciated

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Oct 08, 2020 @ 14:14
    Nik
    0

    Hi John,

    I think the reason this probably doesn't exist is it's to discourage changes to the web.config (or referenced files) on a live site. Every change you make to the web.config file will result in the site restarting, and if you are using a seperate rewriteRules.config, then you need to restart the site some how (normally by editing the web.config) to get the new rules to be reloaded.

    If you need more custom rewrites that are editable, I'd suggest using the Skybrud redirects package which gives you a dashboard for creating rewrite rules, although there are some rules I don't think it can do.

    Just a thought.

    THanks

    Nik

  • JohnAss 18 posts 128 karma points
    Oct 14, 2020 @ 13:23
    JohnAss
    0

    Hi Nik

    Thanks for the reply and sorry for the late response. Im quite bussy atm :)

    The point you are making was something I had in considoration. I completely agree. It does not sound "smart" to change the web.config.

    However, I actually ended up making it anyways.

    And the reason is:

    • Im making a "umbraco-base" for my company
    • The dashboard will only be used by frontend-developers (not customers)
    • All of these changes will be made before we go live (we always have a SEO test before going live)
    • Im the only backend-developer that can write C# - we do however have some developers who are pretty good at rewrites rules in the IISmanager - so its partly for debugging purposes on live-sites

    The way I made is was:

    The dashboard loads and shows all the rules in from the IISRewriteRules.config

    Each rule is binded to a checkbox (the enabled attribute)

    Here the frontender or SEO-guy can check the rules.

    Then we have two buttons: "save changes" and "apply"

    On "save changes" all of the rules will get the new value from the checkbox. Nothing touches the web.config here.

    On "apply" we simply load and save the web.config without changing anything.

    These methods can only be hit if you are logged into the umbraco-backoffice. The dashboard can only be accessed for admin users.

    I have it up and running and its working fine imo.

    If anyone is intrested in the code let me know.

  • Jomar Edaño 1 post 71 karma points
    Apr 25, 2022 @ 11:48
    Jomar EdaƱo
    0

    Hello John, I'm interested in the code can I have a look at it or examples. Thank you very much!

Please Sign in or register to post replies

Write your reply to:

Draft