How to use URL routing with multiple environments?
I have three different environments that I need to be able to use url routing with:
- Debug
- Live
- Demo
The home pages for these three are:
- http://localhost:48060/Login.aspx
- http://192.168.0.145/Live/Login.aspx
- http://www.website.com/Demo/Login.aspx
Both Live and Demo sit in the same Default Web Site as web applications (live is exposed only internally, while demo is exposed externally).
I want to map these to
- http://localhost:48060/login
- http://192.168.0.145/Live/login
- http://www.website.com/Demo/login
Wi开发者_运维百科thout triplicating every route mapping, what is the recommended approach?
Thanks!
Example of how I add the route for Debug env:
routes.MapPageRoute("Login", "login", "~/Views/Login.aspx");
More info:
When I tried adding
routes.MapPageRoute("Login", "login", "~/Live/Views/Login.aspx");
routes.MapPageRoute("Login", "login", "~/Demo/Views/Login.aspx");
the routes didn't work. I received a 404 error when trying visit http://192.168.0.145/Live/login Not sure what the problem is.
I'm using IIS 7.1 for published versions and whatever Win XP pro uses for debug.
Youre "environments" seem to be sub-directories of the root of the application. Because the first of your three URLs does not contain a second value (e.g. "http://localhost:48060/debug/login") it's not going to be easy to define one route for all three.
If these secondary environments are defined as their own applications then you should be able to use the same route in each, but we would need more details to help you further.
Please describe your situation a little better and I will update my answer with more information.
Turned out to be a configuration issue that m$ forgot to mention. Got it working by modifying my web.config to use runAllManagedModulesForAllRequests
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
精彩评论