This article discusses the switch of the protocol from HTTP to HTTPS for Web applications in Visual studio.
- For new Visual Studio Web Project
- ASP.NET MVC Web app
- ASP.NET Core MVC Web app
- For an existing Web Application in Visual Studio
Choose HTTPS for a new app in Visual Studio
This is straightforward: when you create your app, you can choose what you like.
1 - For ASP.NET MVC Web app
We use the current version of Visual Studio 2019 16.11.7 and .NET Framework 4.8 to build the app.
- Start Visual Studio and select Create a new project.
- In the Create a new project dialog, select ASP.NET Web Application (.NET Framework) > Next.
- In the Configure your new project dialog, enter
HTTPS_Project
for Project name > Create.
You will see on the right hand side, under Advanced, there is choice: Configure for HTTPS, by default, it is checked.
2 - For ASP.NET Core MVC Web app
- Start Visual Studio and select Create a new project.
- In the Create a new project dialog, select ASP.NET Core Web App > Next.
- In the Configure your new project dialog, enter
HTTPS_Project
for Project name > Create.
Configure for HTTPS, by default, is in the middle.
Switch HTTP to HTTPS for an existing app in Visual Studio
For the web project configured running on HTTP, right click the project and click properties:
The Project Properties Window is open, click Web Tab, we can see that the Project Url is HTTP protocol.
If we simply change the HTTP protocol here to HTTPS:
It will not work, you will get a page with error:
To fix this error, as suggested from this site:
For an existing project configured for HTTPS, look at the properties pane for the application and set SSL Enabled from true to false.
Left click the Web app project, we have
Change SSL Enabled from true to false
Then, we will have our task done. However, in practice, At first you may get an error
with message:
"You can't remove SSL from this site because this Web project is currently configured to browse with this URL. You need to use the Web property page to change the project URL to the non-secure URL first."
Telling you to change the project URL in the web section of the properties page (right-click the web application folder and select properties) from HTTPS to HTTP first.
Do it
Now, we can Change SSL Enabled from true to false,
Finally, we have to back to switch the HTTP protocol to HTTPS,
Run the app, we have switched HTTP to HTTPS successfully.