Run two Application on Same Port in Visual Studio

2020-07-22 17:20发布

I have run Two Applications in different ports.

One is : http://localhost:12345/

and another one is : http://localhost:50949/

Now I got a cors domain issue, So I want to run those applications on same port number in vs 2012

How can i do it?

2条回答
做个烂人
2楼-- · 2020-07-22 17:24

If you configure Visual Studio to use IIS you can configure both websites under a different Virtual Directory, which will allow you to run them side-by-side. It does require you to have your routing setup correctly to understand the difference between ApplicationRoot and WebRoot, and that you're using the HTML Helpers objects everywhere to setup your routs in links.

You can also configure virtual directories in IIS express if you want to, but I suspect you'll need to dive into the XML to make it work.

查看更多
虎瘦雄心在
3楼-- · 2020-07-22 17:33

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 (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:

  1. MyNamespace.Web on http://mysite/
  2. MyNamespace.Web.Api on http://mysite/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.

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

查看更多
登录 后发表回答