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?
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>
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.
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