Publish a .NET Application to a Windows Server 2022 Instance in Amazon Lightsail
Introduction
Implementation
Create an Amazon Lightsail account
This tutorial is free tier eligible with Amazon Lightsail, but costs may apply.
Already have an account? Sign in
Create a Windows Server 2022 instance in Amazon Lightsail
This tutorial requires that you create a Windows Server 2022 instance in Lightsail. To do so, follow the steps in the Launch a Windows Virtual Machine with Amazon Lightsail tutorial, but make sure to select Windows Server 2022 when choosing the operating system-only instance image.
Install the required roles and features on your instance
You can connect to your Windows Server 2022 instance using the browser-based RDP client in the Lightsail console. After you’re connected, you can install the required server roles and features that will allow you to connect to your instance through Visual Studio and run .NET applications.
1. Connect to your instance
On the Instances tab of the Lightsail home page, choose the RDP quick-connect icon for your Windows Server 2022 instance.
2. Open Server Manager
After the browser-based RDP client window opens, choose the Windows icon and open Server Manager.
3. Turn off IE Enhanced Security Configuration
Choose Local Server in the left navigation menu, then choose On next to IE Enhanced Security Configuration (choosing On turns it Off).
Note: Turning off IE Enhanced Security Configuration will allow you to download resources later in this tutorial.

4. Turn IE Enhanced Security Configuration off for administrators
In the configuration prompt, choose to turn off the feature only for administrators, and then choose OK.

5. Add roles and features
In Server Manager, choose Dashboard in the left navigation menu, then choose Add roles and features.

6. Continue through the wizard
Choose Next in the Add Roles and Features Wizard.

7. Choose an installation type
Choose Role-based or feature-based installation in the Select installation type screen, and choose Next.

8. Select a destination server
Choose Next in the Select destination server screen.

9. Select a server role
Choose Web Server (IIS) in the Select server roles screen. Choose Add features when you are asked if you would like to add the required features. Choose Next.

10. Select features
Choose the features highlighted in this screenshot in the Select features screen, and then choose Next.

11. Review the information about web server roles
Choose Next in the Web Server Role (IIS) screen.

12. Select web server services
Choose the role services highlighted in this screenshot under the Web Server service.

13. Select performance and security services
Choose the role services highlighted in this screenshot under the Performance and Security services.

14. Select FTP server and management tools services
Choose the role services highlighted in this screenshot under the FTP Server and Management Tools services.

15. Select application development services
Choose the role services highlighted in this screenshot under the Application Development service.

16. Confirm selections
Choose Next after you confirm that you selected all of the correct role services highlighted in the previous steps.
17. Restart the destination server
Choose Restart the destination server automatically if required, and then choose Install in the Confirm installation selections screen.
The roles and features will require a few minutes to download and install.

Install Web Deploy on your instance
You must install the Web Deploy 4.0 extension on your Windows Server 2022 instance to enable deployment of web applications and websites to your server.
1. Download Web Deploy
On your Windows Server 2022 instance, open Internet Explorer and download Web Deploy 4.0.
2. Open the file
After the download completes, choose Open file to start the installer.

3. Start installation
Choose Next on the initial Setup Wizard screen.

4. Accept terms
Accept the terms in the license agreement, and choose Next in the Microsoft Web Deploy 4.0 Setup screen.

5. Choose a setup type
Choose Complete on the Choose Setup Type screen.

6. Install Web Deploy
Choose Install to start the installation, then choose Finish to close the installer when the installation is complete.

Install ASP.NET Core 6.0 Hosting Bundle
Because we’re going to publish an ASP.NET Core Web App to the Windows Server 2022 instance, you need to install the ASP.NET Core 6.0 Hosting Bundle.
1. Download Hosting Bundle
On your Windows Server 2022 instance, open Internet Explorer and download ASP.NET Core 6.0 Hosting Bundle.

2. Open the file
After the download completes, choose Open file.

3. Accept the terms
Accept the terms in the license agreement, and choose Install in the Windows Server Hosting Setup screen.

4. Verify installation
After the installation completes, choose Close.

Create an ASP.NET Core Web Application in Visual Studio 2022
In these steps, you will create an application using the ASP.NET Core Web App template in Visual Studio 2022 Community edition. To download and install Visual Studio 2022 Community edition, see the Visual Studio website.
1. Open Visual Studio
Open Visual Studio 2022 Community edition on your local computer (not the Windows Server 2022 instance).
2. Create a project
Choose Create a new project.

3. Configure project
Choose C# in the language dropdown menu. Choose ASP.NET Core Web App in the list of available projects, and choose Next.

3. Configure project
Choose a Project name, and choose Next.

4. Create the project
On the Additional information screen, make sure the Framework selected is .NET 6.0, and choose Create.
After this step, you will have an ASP.NET core website project template that you can edit in Visual Studio. When you are done editing your project, continue to the next section to publish your project to your Windows Server 2022 instance.

Publish your .NET application to your Windows Server 2022 instance
In these steps, you will configure Visual Studio to connect to your Windows Server 2022 instance so that you can publish your .NET core project to your server.
1. Add a firewall rule
For publishing to work from a remote network, you need to add a firewall rule to your Windows Server 2022 instance. Open your Lightsail console and open the Networking tab of your instance. Choose + Add rule and enter 8172 as the port, then choose Create.

3. Choose a publishing target
Choose Web Server (IIS) and choose Next in the Publish screen.

4. Choose Web Deploy
Select Web Deploy and choose Next.

5. Get the public IP
Get the public IP address of your Windows Server 2022 instance from the Lightsail console.

5. Get the public DNS name
Perform a reverse DNS lookup by running nslookup PublicIpAddress in PowerShell to get the public DNS name for your Windows Server 2022 instance’s IP address; this PublicHostname will be used in the next step as the server name.

6. Configure web server connection
On the next screen, enter the following information:
Enter PublicHostname in the Server text box. Replace PublicHostname with the public DNS name of your Windows Server 2022 instance retrieved in the previous step.
Enter Default Web Site in the Site name text box.
This is name of the default website automatically configured when you installed Internet Information Services (IIS) on your Windows Server 2022 instance.
Enter http://PublicHostname in the Destination URL text box. Replace PublicHostname with the public DNS name of your Windows Server 2022 instance retrieved in the previous step.

7. Enter credentials
Enter Administrator in the User name text box. This is the default administrator user name for your Windows Server 2022 instance.
Enter the administrator password in the Password text box.
You can get the administrator password by going to the instance’s management page in the Lightsail console, and choosing Retrieve default password under the Connect tab.

8. Validate the connection
Choose Validate Connection to test the connection. You might get a certificate error like the one in the screenshot when connecting the first time. This is because the server uses a default certificate and you can safely accept it if the hostname displayed matches the one you intended to connect to.
A checkmark icon will appear if the validation is successful. If the validation is unsuccessful, confirm that you entered the correct information into the form (confirm the administrator password and the IP address).

9. Monitor profile creation
Choose Finish, then choose Close when the Publish profile creation progress completes successfully.

10. Publish your project
Choose Publish in Visual Studio when you are ready to publish your project to your server.

11. Check the output
The Output in Visual Studio will show a successful message if your project was successfully published to your server.

11. Check the output
Browse to the PublicHostname of your Windows Server 2022 instance to confirm that the project was successfully published.
Your project was successfully published if you see a page similar to the following screenshot.

Clean up resources
In the following steps, you clean up the resources you created in this tutorial. It is a best practice to delete instances and resources that you are no longer using so that you are not continually charged for them.
1. Delete the instance
On the Instances tab of the Lightsail home page, choose the ellipsis (⋮) icon next to the Windows Server instance you just created and choose Delete.

2. Confirm deletion
Choose Yes, delete from the prompt.

Conclusion
Congratulations! You have published a .NET core web application to your Windows Server 2022 instance in Amazon Lightsail.
Amazon Lightsail is a great choice to develop, build, and deploy a variety of applications like content management systems, websites, and other platforms.
Did you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages