0

I have a app root :localhost/Product

I want to attach a string to my root url localhost\stringName

stringName will be read frm config file and set to the end of url, followed by controller and action name eg: localhost\Product\stringName\controller\Action and stringName needs to be preserved throughtout the app with all redirects.

Please help

2 Answers2

0

Check out: http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC

You need to do some research into custom url routes

Steve Stokes
  • 1,200
  • 18
  • 36
0

You can change default routing like this:

routes.MapRoute(
     name: "Default",
     url: "{controller}/stringName/{action}/{id}",
     defaults: new { controller = "DefaultPage", action = "Index", id = UrlParameter.Optional }
);

From your RouteConfig.cs file. OR if you upgrade your application from mvc 4 to mvc 5 you can use the attribute routing you can read more here.

Update:

Try this in default route:

string stringName = WebConfigurationManager.AppSettings["stringName"].ToString()
routes.MapRoute(
    name: "Default",
    url: stringName + "/{controller}/{action}/{id}",
    defaults: new { controller = "Page", action = "Index", id = UrlParameter.Optional }
);
);
TotPeRo
  • 6,561
  • 4
  • 47
  • 60
  • The above route will not match because..my request doe not have stringName to begin with..it gets added on sessionStart in global.asax. – user3667110 May 23 '14 at 20:43
  • then you can implement IRouteConstraint like here: http://stackoverflow.com/questions/16026441/dynamic-routes-from-database-for-asp-net-mvc-cms – TotPeRo May 24 '14 at 20:57