Search code examples
c#asp.net-mvcvirtual-path

ASP.net MVC virtual path


I would like to add a virtual path to my asp.net application. In visual studio there is a setting virtual path I'd like to put a version number as the part of the url of my application.

It was like http://localhost:53278/{controller}/{action}

I would like to add an extension like this

http://localhost:53278/0.0.0.1/{controller}/{action}

Somewhere I need to configure in my asp.net mvc 3 application ?

Thanks


Solution

  • Are you trying to do this dynamically?

    Areas can be used if that isn't desired, but in the end it represents a different route entry. That route entry can be dynamically added or hard coded.

    When adding routes you can do something like

    // used System.Reflection.Assembly.GetExecutingAssembly().GetName().Version to get the version then build the string you want
    
    context.MapRoute(
                    "Versioned_default",
                    "<YOURVERSIONSTRING>/{controller}/{action}/{id}",
                    new { action = "Index", controller = "Home", id = UrlParameter.Optional }
                );