Introduction
This article demonstrates the step-by-step approach to deploying and publishing a .NET 7 application to Internet Information Services (IIS).
Step 1. IIS Configuration (Optional)
If IIS is not already configured, we could follow the steps below to make it enabled.
Open Control Panel > Programs > Programs and Features > Turn Windows features on or off.
Expand Internet Information Services, World Wide Web Services, and Application Development Features.
Step 2. Install the .NET Core Hosting Bundle on the IIS server
Make sure you have a server with IIS installed and properly configured. Otherwise, you can follow the above optional steps.
Ensure that the necessary components for hosting .NET 7 applications are enabled. The hosting bundle installs the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module.
Please click on the link below to download and run Installer on the Windows server.
Please restart the server after installation.
Step 3. Publish to a File Folder
In Visual Studio, right-click the project you want to deploy and choose publish.
Click on Folder > Next > Folder location will populate the default path as “bin\Release\net7.0\publish\”. > Click on Finish > Publish.
OPTIONAL - Alternative way to generate published files,
Open a terminal and navigate to the root directory of your .NET 7 project.
Run the following command to publish your application:
dotnet publish -c Release -o PublishOutput
This will compile your application in Release mode and generate the necessary files in the Publish folder.
Step 4. Copy Files to Preferred IIS Location
Now, copy the published files to the location where they should be stored. In our case, let's copy the files to C:\inetpub\wwwroot\EmpoyeeAPI.
Step 5. Create an Application in IIS & Configure Application Pool
Open the IIS Manager on your server.
Create a new site or use an existing site to host your application. Right-click on the "Sites" node and choose "Add Website".
Provide a site name, a physical path (point it to the PublishOutput folder from the previous step), and an optional hostname.
Make sure the .NET CLR version is set to "No Managed Code" since .NET 7 uses the .NET Core runtime.
Click on Application Pools > Select application pool name > Set the .NET CLR version to "No Managed Code" > Set the pipeline mode to "Integrated".
Step 6. Test your app after deployment
After configuring the site, try accessing it through a web browser. Make sure everything is working as expected.
Important points, as we are deploying Web API in our case, generally, Swagger UI middleware is kept under the app.Environment.IsDevelopment() check. For demonstration purposes, I kept this swagger middleware outside of this condition so that we can check the page in a browser.
Happy Reading!