简体   繁体   English

ASP.net MVC虚拟路径

[英]ASP.net MVC virtual path

I would like to add a virtual path to my asp.net application. 我想向我的asp.net应用程序添加虚拟路径。 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. 在Visual Studio中,有一个设置虚拟路径,我想将版本号作为应用程序URL的一部分。

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

I would like to add an extension like this 我想添加这样的扩展名

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

Somewhere I need to configure in my asp.net mvc 3 application ? 我需要在asp.net mvc 3应用程序中进行配置吗?

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. 除了扩展名外,在URL中包含句点通常不是一个好主意。 0-0-0-1 would work. 0-0-0-1会起作用。 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. 在Visual Studio中,右键单击解决方案资源管理器中的MVC项目(该项目,而不是解决方案),然后在网页上单击鼠标右键(如果使用的是默认开发服务器),则只需更改虚拟路径并保存即可。 Done. 做完了

If you're using IIS, you have to type in the path and click Create Virtual Path. 如果使用的是IIS,则必须输入路径,然后单击“创建虚拟路径”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM