如何将.NET MVC和Web API项目构建和发布到它们的不同文件夹 [英] How to build and publish .NET MVC and Web API projects to their different folders

查看:257
本文介绍了如何将.NET MVC和Web API项目构建和发布到它们的不同文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含MVC和WebApi项目的解决方案.我要做的就是单击一下即可将它们都发布. 我希望MVC项目转到根文件夹..\MyApp\,将WebApi转到..\MyApp\Api\.

I have a solution which contains MVC and WebApi projects. What I want to do is to to publish them both with a single click. I would like MVC project to go to a root folder ..\MyApp\ and WebApi to ..\MyApp\Api\.

我认为我已经看到了这样的解决方案,但是我在任何地方都找不到.

I think I've seen such solution, but I just cannot find it any where.

推荐答案

物理路径将由您的发布方法确定.您可以将发布向导设置为仅指向所需的物理路径.然后,您必须配置IIS以确保两个应用程序可以共存.

The physical path is going to be determined by your publishing method. You could set up the publishing wizard to just point to the physical path that you want. Then you'd have to configure IIS to ensure that both applications can coexist.

到目前为止,路由将由Web API的内置路由来解决.如果您将Web服务器配置为将应用程序托管在/myapp上,并将API托管在虚拟目录中的/myapp/api上,则需要更改Web API中的路由以消除api前缀.

As far the routing, that will be taken care of by Web API's built in routing. If you configure your web server to host the application at /myapp and the API in a virtual directory at /myapp/api, you'll need to change the routing in Web API to eliminate the api prefix.

config.Routes.MapHttpRoute(
   name: "DefaultApi",
   routeTemplate: "api/{controller}/{id}", //remove "api/"
   defaults: new { id = RouteParameter.Optional }
);

这将告诉Web API将所有路由都挂在/而不是/api上,因为/api现在是应用程序根目录所在的位置,并且该路径将来自IIS.

This will tell Web API to hang all of it's routes off of / instead of /api since /api is now where the root of the application is hosted, and that path will come from IIS.

要进一步回答问题,请指定您要使用的发布方式.

To further answer the questions, please specify what method you are using to publish.

这篇关于如何将.NET MVC和Web API项目构建和发布到它们的不同文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆