且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Visual Studio中的同一端口上运行两个应用程序

更新时间:2023-11-22 19:59:40

我要添加另一个带有其他选项的答案.使用成熟的IIS具有一些优点,但是并不是每个人都安装了IIS,甚至没有安装它的选项.默认情况下,Visual Studio将为每个项目分配端口,并在IIS Express中创建它们.但是,您可以在项目属性中轻松覆盖它.

I'm adding another answer with another option. Using full-blown IIS has some advantages, but not everyone has it installed or even has the option to install it. Visual Studio, by default, will assign ports to each project and create them in IIS Express. However, you can easily override it in the project properties.

作为一个例子,我可能有两个看起来像这样的项目:

As an example, I might have two project that look like this:

  1. MyNamespace.Web (当前正在监听端口12345)
  2. MyNamespace.Web.Api (当前正在监听端口54321)
  1. MyNamespace.Web (currently listening on port 12345)
  2. MyNamespace.Web.Api (currentlly listening on port 54321)

当我部署它们时,我将它们运行在不同的虚拟目录中,如下所示:

When I deploy these, I'll run them in different virtual directories like this:

    http://mysite/ 上的
  1. MyNamespace.Web
  2. MyNamespace.Web.Api http://mysite/api

要在带有IIS Express的Visual Studio中模拟这一点,我可以转到 MyNamespace.Web.Api 的项目属性,并将Project Url(在服务器"下,在"Web"选项卡上)更改为 http://localhost:12345/api/并单击创建虚拟目录"按钮.

To mimic this in Visual Studio with IIS Express, I can go to the Project Properties of MyNamespace.Web.Api and change the Project Url (under Servers, on the Web tab) to http://localhost:12345/api/ and click the "Create Virtual Directory" button.

我的两个项目现在都在IIS Express上运行,使用相同的端口,但位于不同的虚拟目录中.

My two projects are now running on IIS Express, using the same port, but in different virtual directories.