In this guide, we will walk you through the step-by-step process of setting up and deploying an ASP.NET Core website on a Windows Server. This tutorial will help you configure your server, install necessary components, and get your application up and running efficiently.
Step-by-Step Guide to Host ASP.NET Core on Windows Server
1. Prepare Your Windows Server
- Ensure Your Server is Up-to-Date:
- Open Windows Update and install any pending updates.
2. Install .NET Core Hosting Bundle
- Download the .NET Core Hosting Bundle:
- Go to the .NET download page and download the .NET Core Hosting Bundle installer.
- Run the Installer:
- Run the downloaded installer and follow the prompts to complete the installation.
3. Install Internet Information Services (IIS)
- Open Server Manager:
- Click on "Add roles and features".
- Install Web Server (IIS):
- Follow the wizard to install the Web Server (IIS) role.
- Ensure the following features are selected:
- Web Server > Common HTTP Features > Static Content
- Web Server > Common HTTP Features > Default Document
- Web Server > Application Development > .NET Extensibility 4.7
- Web Server > Application Development > ASP.NET 4.7
- Web Server > Application Development > ISAPI Extensions
- Web Server > Application Development > ISAPI Filters
- Management Tools > IIS Management Console
- Restart Your Server:
- After installation, restart your server to apply changes.
4. Publish Your Application
- In Visual Studio (on your development machine):
- Right-click on your project > Publish.
- Choose "Folder" as the target.
- Publish the project to a folder.
- Copy the Published Files to the Windows Server:
- You can use RDP, FTP, or any other file transfer method to copy the published files to the server.
5. Configure IIS
- Open IIS Manager:
- Press Win+R, type
inetmgr
, and press Enter.
- Press Win+R, type
- Add a New Website:
- Right-click on "Sites" in the Connections panel and select "Add Website".
- Fill out the details:
- Site name: Your site name.
- Physical path: The path to your published application.
- Binding: Configure the IP address, port, and hostname as needed.
- Click "OK" to create the site.
- Set the Application Pool:
- Ensure the application pool for your site is set to "No Managed Code".
- Open "Advanced Settings" of the Application Pool and set the ".NET CLR version" to "No Managed Code".
6. Test Your Application
Open your browser and navigate to your server's domain or IP address to see your ASP.NET Core application running.
Additional Tips
- Security: Ensure your server's firewall allows traffic on the necessary ports (e.g., port 80 for HTTP and port 443 for HTTPS).
- SSL/TLS: Set up SSL/TLS for your website using a certificate from a trusted Certificate Authority (CA).
- Monitoring and Logs: Use tools like Event Viewer and IIS logs to monitor your application and troubleshoot issues.
By following these steps, you can successfully run your ASP.NET Core application on a Windows Server.