I've been developing a product for 2 years which is being sold by ourselves and partners. Now the manager wants to give the source code to our partners which will be only used as Demo apps with a Demo License.
All the demo module has been already developed but I need to show "Demo" on the route (url) when the license says so.
Example:
Every call to
/Controller1/Action1
Must transform the URL to
/Demo/Controller1/Action1
First try:
routes.MapRoute(
name: "DefaultDemo",
url: "Demo/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
However, this will partially work because I need to set "Demo" on every call to Controller/Action I've in my app.
Second try:
routes.MapRoute(
name: "DefaultDemo",
url: "{demo}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { demo = "Demo" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, demo = "Demo" }
);
In this one, I tried to set it as a variable and "Demo" as a constraint of the that variable, to prevent someone to change it to other text.
Then I tried to use the "Default" route as Redirect to the other one, by setting the parameter "demo", however this obviously failed since it doesn't work this way.
Third try:
var demoRoute = routes.MapRoute(
name: "DefaultDemo",
url: "{demo}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { demo = "Demo" }
);
routes.Redirect(x =>
x.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional, demo = "Demo" })
)
.To(demoRoute);
In the last example I tried to use RouteMagic nugget to redirect the old "Default" route to the Demo one, but it didn't work.
Anyone who did something similar?