Last post Mar 17, 2016 09:35 AM by lextm
Mar 05, 2016 09:38 AM|NTMS2016|LINK
I have build a very small MVC web application. Later I add very small Web API. It takes 3 parameters and returns 4 parameters (with use of Get Method).
Every time I run my solution I can see IIS Express running bottom right of the toolbar. When I use mouse and right click on running IIS Express I can see 2 running app. First one is my MVC app and second one is my Web API. Both shows different port. Why?
Okay maybe some internal process uses different port. This I can understand. But why Web API in internet editor shows the port number and my web app isn't? This I don't get it.
If I use my both application in real world how to consume my Web API if there is a port that keep changes? If I close my VS2015 and run it again and use my Web API the port will change to something else. My last question is this. Can I set programmatically
my Web API port to such as 8000 vs 8080? So when I run my Web API in real world, I can consume from diffrenet machine (mobile, embedded devize etc.).
Mar 05, 2016 11:18 AM|bobj181|LINK
In visual Studio, is the Web Api and MVC application to separate projects? If so, then that is why you see to different port numbers assigned to the two applications. When you start a project it randomly picks a port number to run off of. The ports also
should not be changing, they should stay consistent with the random ports.
You do not have to progammically manage ports for IIS. Not knowing you exact hosting situation, I can't 100% tell you exactly what it will look like, but to your question about assigning ports, yes you can. However, if you are using a hosting service,
then that may or may not be possible.
Mar 08, 2016 06:41 AM|Yohann Lu|LINK
First one is my MVC app and second one is my Web API. Both shows different port. Why?
You may create two Web applications (MVC and API) in the solution. When you deploy them in the host, the URI pointing to two applications certainly can not be homologous (the same address and port number). So they have a different port number.
You can also add a web API project to MVC 4/5 project, so they are a program that runs in the same address.
You can refer the following steps:
Step 1: Install Web API to your MVC project. Project - Right click - Manage Nuget Packages - Search for Web API.
Step 2: Add WebApiConfig.cs to the App_Start/ folder
Step 3: Add GlobalConfiguration.Configure(WebApiConfig.Register) to Global.asax.cs.
Step 4: Add Web API Controller.
Step 5: Test it in IE.
Add Web API to an existing ASP.NET MVC 4 Web Application project for your reference:
Can I set programmatically my Web API port to such as 8000 vs 8080?
You can set the debug port in your project like the following steps (does not change when debugging).
1: Right-click the project and choose Properties
2: Choose Web
3: Modify the Project Url attribute value
Mar 17, 2016 09:35 AM|lextm|LINK
Random port numbers are used only when you are developing the web apps.
Visual Studio/IIS Express tend to use random numbers to avoid potential conflicts with the applications running on your development machine (some apps occupy port 80 or 443 for their purposes), and also a port number > 1024 does not require administrator
permissions to monitor. Thus, that's mainly for convenience.
At deployment time, you can publish them to IIS with standard port numbers (such as 80 or 443), and that's controlled by IIS configuration (site bindings). Web API apps are developed in a neutral way that it should be able to run at any port at deployment
time, and you don't need to set too early.