Saturday, 2 October 2021

Get started with Swagger and ASP.NET Core Web API app

 

  1. In the Visual Studio, create a new project: ASP.NET Core Web Application
  2. Select project template: API
  3. After the project is created follow instructions as below
    https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio
  4. Add NuGet Package: Swashbuckle.AspNetCore
  5. Modified startup.cs file as below

  6. Once is done, rebuild the project and debug
  7. When the page has opened up, navigate to /swagger

First deploy to the server

  1. Right-click on the project and publish
  2. Copy the Target Location
  3. Open IIS
  4. Create a new website
  5. Map the Physical Path to the Target Location
  6. Go to Application Pools
  7. Edit Application Pool
  8. Set .NET CLR version: No Managed Code
  9. Install ASP.NET Core 3.1 Runtime - Windows Hosting Bundle to the server 
    https://dotnet.microsoft.com/download/dotnet/3.1


If you haven't register the domain on public DNS, in order to view your Swagger page on you local machine, you should update hosts file on your machine.
To do so, open hosts file on the your machine at c:\Windows\System32\Drivers\etc

and append to the file content as:


[IP Address] [API domain name]


Example:

127.0.0.1    tech--about.com

No comments:

Post a Comment

SMTP Mail Sending Failure - Connection troubleshooting

Background: I have encounter issue when sending email from my application server via SMTP server. The syndrome is only smaller size email is...