DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How To Validate Names Using Java
  • Alexa Skill With .NET Core
  • Why Mocking Sucks
  • Implementing CRUD Operations With NLP Using Microsoft.Extensions.AI

Trending

  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Host and Publish .Net Core 6 Web API Application on IIS Server

Host and Publish .Net Core 6 Web API Application on IIS Server

In this step-by-step guide, learn and discuss how to host and publish the.NET Core 6 Web API on the IIS Server. Happy Coding!

By 
Jaydeep Patil user avatar
Jaydeep Patil
·
Aug. 25, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.0K Views

Join the DZone community and get the full member experience.

Join For Free

We are going to discuss how to host and publish the.NET Core 6 Web API on the IIS Server.

Introduction

Basically, Internet Information Service (IIS) is the flexible and general-purpose web server provided by Microsoft that will be run on Windows and used to serve requested files.

Required Tools

  • IIS Manager
  • .NET Core SDK 6
  • Visual Studio 2022

Let’s start,

Step 1

Create a new .NET Core Web API Project.

Create a new .NET Core Web API Project

Step 2

Configure your new project.

Configure your new project

Step 3

Provide additional information like .NET Framework Version, Open API, and HTTPS.

Provide additional information like .NET Framework Version, Open API, and HTTPS.

Step 4

Project Structure.

Project Structure.

Step 5

Create the Product Controller, add one endpoint inside that class, and also check other files that are created by default.

C#
 
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProductsController : ControllerBase
    {
        [HttpGet]
        [Route("list")]
        public IDictionary<int, string> Get()
        {
            IDictionary<int, string> list = new Dictionary<int, string>();
            list.Add(1, "IPhone");
            list.Add(2, "Laptop");
            list.Add(3, "Samsung TV");
            return list;
        }
    }
}


Program.cs file

C#
 
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();


Here also, you can see that we configure the HTTP request pipeline for both the development and Production environments.

WebAPI.csproj file

C#
 
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>
</Project>

launchSetting.json file

JSON
 
{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:11254",
      "sslPort": 44315
    }
  },
  "profiles": {
    "WebAPI": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7047;http://localhost:5047",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}


Step 6

Run your application and hit the API endpoint using Swagger UI.

Run your application and hit the API endpoint using Swagger UI.

Step 7

Check if all IIS Services are running on your system properly or not. If not, then open the control panel, go to Program and Features, and click on Turn Windows Feature on or off.

Check if all IIS Services are running on your system properly or not.

If not, then open the control panel, go to Program and Features, and click on Turn Windows Feature on or off.

Apply the changes as I showed you in the above image, click on Apply, and then restart your computer.

Step 8

After restarting your computer, you will see IIS Manager in the search box. Open it.

After restarting your computer, you will see IIS Manager in the search box. Open it.

Now, check your running IIS using localhost in the browser.

Now, check your running IIS using localhost in the browser.

Step 9

Install ASP.NET Core 6.9 Runtime — Windows hosting bundle installer.

Step 10

Now, we are going to publish our application for that, right-click on WebAPI Project and click on Publish.
right-click on WebAPI Project and click on Publish.

Publish

As you see, it will take the default path, so change that path to c:\inetpub\wwwroot\publish after creating the publish folder over there.

Step 11

Here, you can see all the configurations related to publishing, like path and some environmental variables, and later on, click on Publish.

configurations related to publishing

Step 12

Open IIS Manager and create a new Web Application after right click on the sites.

Open IIS Manager and create a new Web Application after right click on the sites.

Step 13

Click on Web API, and on the right side, you can see the browse option, so click on that and open the application inside the browser.

Click on Web API, and on the right side, you can see the browse option, so click on that and open the application inside the browser.

Step 14

In the browser, when you hit the Web API endpoint using Swagger, then will see the following list of products as an output.

In the browser, when you hit the Web API endpoint using Swagger, then will see the following list of products as an output.

Conclusion

In this article, we discussed .NET Core 6 Web API hosting and publishing-related things using IIS and things related to that step-by-step. I hope you understand everything.

Happy Coding!

API Software development kit Web API application Host (Unix)

Published at DZone with permission of Jaydeep Patil. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Validate Names Using Java
  • Alexa Skill With .NET Core
  • Why Mocking Sucks
  • Implementing CRUD Operations With NLP Using Microsoft.Extensions.AI

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!