Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure ASP.NET Routing in Web.config

Is there a way to configure ASP.NET routing in the web.config file? I do not need anything fancy. If a user visits /myApp/list, I want to load /myApp/list.html. However, I do NOT want the address bar to change.

Is this possible? If so, how?

like image 475
Node Newbie Avatar asked Feb 15 '23 01:02

Node Newbie


2 Answers

The best way is to use UrlRewrite module in IIS: http://www.iis.net/learn/extensions/url-rewrite-module

How you make this rule into web.config after installing UrlRewrite:

<system.webServer>
    <rewrite>
      <rules>
          <rule name="my-first-url-rule" stopProcessing="true">
            <match url="^/myApp/list$" />
            <action type="Rewrite" url="/myApp/list.html" appendQueryString="true" />
          </rule>
      </rules>
    </rewrite>
</system.webServer>
like image 125
Wagner Leonardi Avatar answered Feb 27 '23 13:02

Wagner Leonardi


As of now there is No out-of-the-box way to configure routes in web.config file.

It seems vision was/is to add new routes on Application Start. This doesn't stop us from creating custom configuration section and reading routes from there.

These are guesses why. Most of the time, it seems, adding new routes could be prone to introduction of routing bugs and should be followed up with good regression testing. And therefore it probably will be done as part of new product release anyway. Perhaps that could be one the reasons why it's not configurable through configuration file. Another reason could be that routes rules can be quite complex to put them into xml format - constraints, custom route handlers,etc.

like image 32
YuryP Avatar answered Feb 27 '23 12:02

YuryP