Localhost Not Found: Creating .NET 2.1 Applications that Listen on Port 443
In this article, we will explore the process of creating .NET 2.1 applications that listen on port 443, which is the default port for HTTPS traffic. This is a site-focused guide, intended to provide detailed context on the topic, including key concepts, subtitles, and code blocks.
Understanding the Issue
If you have encountered the error "Localhost not found" when trying to access a .NET 2.1 application on your local machine, it is likely that the application is not listening on the correct port. By default, .NET 2.1 applications listen on port 5000 for HTTP traffic and port 5001 for HTTPS traffic. However, if you want to access the application using the default HTTPS port (443), you will need to make some changes to the application's configuration.
Configuring Your .NET 2.1 Application to Listen on Port 443
To configure your .NET 2.1 application to listen on port 443, you will need to modify the application's launchSettings.json file. This file is located in the Properties folder of your application's project directory.
$dotnet new webapi -n MyApp
$cd MyApp
$code Properties/launchSettings.json
Once you have opened the launchSettings.json file, you will need to modify the "iisExpress" profile to listen on port 443. Here is an example of what the modified profile might look like:
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"applicationUrl": "https://localhost:443;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Note that we have changed the "applicationUrl" property to include both HTTP and HTTPS traffic on port 443. We have also set the "launchBrowser" property to true, which will automatically open your default web browser to the application's URL when you start the application.
Testing Your .NET 2.1 Application on Port 443
To test your .NET 2.1 application on port 443, you can use the following command:
$dotnet run --launch-profile IISExpress
This will start your application and open your default web browser to the application's URL. If everything is configured correctly, you should be able to access the application using the URL https://localhost.
Troubleshooting Common Issues
If you encounter any issues when trying to access your .NET 2.1 application on port 443, here are some troubleshooting steps you can try:
- Make sure that port 443 is not being used by another application. You can check this by running the command
netstat -an | findstr :443in a command prompt. - Make sure that your firewall is not blocking traffic on port 443. You can check this by disabling your firewall temporarily and trying to access the application again.
- Make sure that your .NET 2.1 application is configured to use HTTPS. You can check this by looking for the
app.UseHttps()method in the Startup.cs file.
In this article, we have explored the process of creating .NET 2.1 applications that listen on port 443. We have covered the following key concepts:
- Understanding the "Localhost not found" error
- Modifying the launchSettings.json file to listen on port 443
- Testing the application on port 443
- Troubleshooting common issues