Вопрос

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

Это было полезно?

Решение

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 }
            );

Другие советы

It's generally not a good idea to include periods in the url, other than for extensions. 0-0-0-1 would work. In visual studio, right click on the MVC project in solution explorer (the project, not the solution) and on the web page, if you're using the default development server, then just change the virtual path and save. Done.

If you're using IIS, you have to type in the path and click Create Virtual Path.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top