Introduction
This article show how to select a specific page and port in the Web API. Here we define the specific port for execution of the application. The application can execute on the defined specific port. Now let's see the example of the application.
Create an Web API Application.- Start Visual Studio 2012.
- From the Start window select "New Project".
- Then select "Installed" -> "Visual C#" -> "Web".
- Select "MVC4 Web Application" and click on the "OK" button.

- From the "MVC4" window select "Web API".

- In the Solution Explorer.
- Double-click on the properties.

- Now open a property window.
- Select "Web" and select the "Specific Page" Radio Button and type the page.
- Now select "Use Visual Studio Development Server" and "Specific port" and enter the port.

Now execute the application. The application will use port "8384".

- In the "Solution Explorer".
- Right-click on the "Model" -> "Add" -> "Class".
- Select "Installed" -> "Visual C#".

- Select "Class" and click on the "Add" button.
Add the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace SelectPortWebAPI.Models
- {
- public class Product
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string category { get; set; }
- }
- }
- In the "Solution Explorer".
- Expand the "Controller" folder.
-
Select the "ValuesController".

Add the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using SelectPortWebAPI.Models;
- namespace SelectPortWebAPI.Controllers
- {
- public class ValuesController : ApiController
- {
- // GET api/values
- public Product Get()
- {
- return new Product
- {
- Id = 1,
- Name = "Keyboard",
- category = "Hardware"
- };
- }
- }
- }
Now again execute the application. it uses the port "8384" and the "api/values" page. It can not use the other port.


prideaux90Posted Jul 5, 2022, 8:26 AM
The article says updated Jan 27, 2021. Then WHY are you still using VS 2012? That is ridiculous !!
prideaux90Posted Jul 5, 2022, 8:25 AM
The article says Updated Jan 27, 2021.
Amol TeliPosted Jan 24, 2019, 3:27 AM
Thanks....