Enable SSL in Visual Studio - c#

I have enabled SSL in Visual Studio as shown below:
I have also set the below:
When I access the website via IE (via Visual Studio debugging) I see this:
When I access the website via Firefox (via Visual Studio debugging) I see this:
There is no option to progress to the website in either Firefox or IE. I have spent all day trying to understand what is wrong. What am I doing wrong?

I see this EXACT problem from time to time, when using SSL, and have found that (especially when working on someone else's project in a team environment) the Visual Studio project web settings (SSL ports) sometimes get messed up. Here's what I do to fix them:
In Solution Explorer, click your project.
Hit the F4 key (view properties).
Copy the URL (NOT the SSL URL).
Paste the URL into the Project Url on the Web Tab, Save.
In Solution Explorer, click your project.
Hit the F4 key (view properties).
Change SSL Enabled to false.
Change it back to true. There should be a new SSL URL. Copy it.
Paste the new SSL URL into Project URL on Web tab. Click Create Virtual Directory.
Click Override application root URL, and paste in SSL URL. Save.
This always solves the issue for me.

Say you have a .NET MVC or Web API project and you’d like to run it on SSL. In other words you’d like to start up the project on a URL similar to https://localhost:xxxx.
The first step is easy. You just select the MVC/Web API project name in the solution and locate the property called “SSL Enabled” in properties window:
The same properties window will also show the HTTPS url for the application. In the above example it’s https://localhost:44300/. Copy that URL and go to the project properties window. Locate the Web tab and override the Project Url property with the https address:
Start the application. You’ll likely get a message in the browser saying that the localhost address is not trusted, you can continue to the website at your own risk. Here’s a Chrome example in Swedish:
The problem is that the certificate that was installed automatically for you by Visual Studio is not trusted. You can locate the certificate in the Personal folder of the computer-level certificates in the certificates snap-in:
If you double-click the certificate you’ll see that it’s not trusted:
The message also provides the solution: the certificate must be imported into the trusted root certification authorities folder. You’ll see that as a folder in the same snap-in just below “Personal”. So how can we do that?
EXPORT
Right-click the certificate
Select All Tasks
Export… from the context menu.
Click Next on the certificate export wizard.
Leave the “Do not export the private key” option untouched, click Next.
Accept the default on the next screen, i.e. “DER encoded binary X.509” should stay selected, then click Next.
Provide a name and a location for the exported file. Call it “localhost” and save it in a location where you can easily find it.
Click Next and the Finish.
There should be a popup message saying that the export was successful.
IMPORT
Next right-click the folder called Trusted Root Certification Authorities and select All Tasks
Import… from the context menu.
Leave the “Local Machine” option untouched in the certificate import wizard, click Next.
Browse to the certificate you saved just before.
Click Next and accept all the default values along the way until you reach the end of the wizard.
There should be a message saying that the import was successful.
If you now go back to the Personal store and double-click the localhost certificate then you should see that it’s trusted:
OK, let’s start the .NET web project again, the opening page should open without any warning. If you still see the same issue then test it a brand new browser session, e.g. here in IE:
You can also view the extracted certificate from the browser window. Here’s an example from IE:

#MattW I am using Mac and was facing this issue. I am using Visual Studio 2019 for Mac on macOS Catalina. I opened the "Project Options" for my project and changed "HTTP" to "HTTPS" in "App URL" under Default Run Configuration for ASP.NET Core
I already had a self-signed certificate for localhost, so Visual Studio gave me a message box asking me to use that Development certificate from Keychain. It asked for my password and used the certificate. The application worked without any issue on "HTTPS"
In case you do not have the development certificate you can generate one, using the following command in your Mac:
dotnet dev-certs https --clean
dotnet dev-certs https --trust
Read more at https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-3.1&tabs=netcore-cli

If you have a Web Site project, with the globe icon in Solution Explorer, enabling SSL goes a little different from a Web App project, with the globe in a rectangle, to which the other answers apply.
The Web Site project does not have the Web Tab. Instead, copy the SSL URL from the project properties (F4) to the Start Url in the project property pages (Shift F4). This step is optional, but if you don't do it, you will have to type the SSL port number manually in your browser.
Besides, for any type of web project, it does not really matter which port number you enter in Properties. The simplest is to accept the number filled in as default by VisualStudio, but another free port number will work just as well.
Of course, you will work with a self-signed certificate, i.e. signed by VS. So the browser might complain about this, and in order to debug your project with SSL, you will have to accept an exception in the browser.

Related

Server Certificate Error on publish, .Net core 5.0, IIS server

I am trying to publish my .net core 5.0 application to our IIS Server. Every time I do I keep getting the following error:
Severity Code Description Project File Line Suppression State
Error Web deployment task failed. (Connected to the remote computer ("myServer") using the specified process ("Web Management Service"), but could not verify the server’s certificate. If you trust the server, connect again and allow untrusted certificates. Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CERTIFICATE_VALIDATION_FAILED.)
I found this post over the same issue. No matter what configuration I use in my publish profile though it does not seem to work. I am a bit confused that the publish profile I imported does not contain PropertyGroup information or anything like that. Just the publishProfile tag with relevant information.
PublishSettings:
Here are my publish settings. What do I need to add in order to get my publishing of the app to ignore the server cert? Again I just want to say I tried adding the AllowUntrustedCertificate and multitude of other suggestions from that other post. Is that setting supposed to go inside the publishProfile information or just right after it within the PublishData? Either way nothing I do works.
<?xml version="1.0" encoding="utf-8"?>
<publishData>
<publishProfile
publishUrl="https://MYSERVER:8172/msdeploy.axd"
msdeploySite="ToolController"
destinationAppUrl="http://myWebSite"
mySQLDBConnectionString=""
SQLServerDBConnectionString=""
profileName="Default Settings"
publishMethod="MSDeploy"
userName="myUserName" />
</publishData>
I am also using Visual Studio 2019 in case that helps at all.
Okay so I am not sure why but using the normal method I typically do. By going to the IIS server -> right clicking the site -> Deploy -> Configure Web Deploy Publishing was not working at all.
Instead I opted to use the visual studio option of generating the publish file by doing Web Server (IIS) -> filling in the relevant info. I then added the
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
and everything worked fine.

ClickOnce deployment: Why is there a 404 error on a URL which, if pasted into the browser, has no problems?

I've published a half dozen apps written in C# using Visual Studio and ClickOnce to IIS running on my development PC but with one solution, which has a VB.NET main project and C# class library, I'm getting an error message: Invalid URI: The hostname could not be parsed.
The app is being launched via the launch link in the publish.htm file. Edge asks if I want to open it. I click the OPEN button and the app is downloaded and the progress bar finishes and then there's the popup error message saying that the URL could not be parsed.
When I check the IIS logs it looks like this:
https://mypc/apps/foo/publish.htm 404 0 2 1
But if I paste the URL https://mypc/apps/foo/publish.htm into the Edge browser's address box, the page is opened in the browser without any issue:
So I don't understand the 404 error. The other apps, all of which can be launched without issue from their publish.htm page, are published in identical manner, to the same website location in sibling folders:
https://mypc/apps/foo2/publish.htm
The structural differences between this solution and the others are
the EXE project of this problem solution is written in VB.NET and there is another project in the solution written in C# that produces a class library and
in the problem solution on the EXE's Properties->Application tab, there are two buttons: Assembly Information and View Windows Settings whereas on all the other working apps there is no View Windows Settings button on that tab and
on the working applications there is a Manifest option on the Application tab, where one of the choices is "embed manifest with default settings" whereas on the VB project's Application tab there is no such Manifest dropdown visible.
I hope there is some clue in these details. What am I missing and how to proceed to troubleshoot this?

UWP - No certificate found with the supplied thumbprint

I have a UWP app I work on from two difference devices. After the latest Visual Studio 2019 update I began receiving this error:
No certificate found with the supplied thumbprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The app previously had the temporary key Visual Studio used to auto generate that it no longer does. I generated a new key file from the instructions at this link
https://learn.microsoft.com/en-us/windows/msix/package/create-certificate-package-signing and that worked on my desktop. I was able to select the certificate in the package manifest, update the "PackageCertificateThumbprint" in the csproj file and then both build and create the sideload package.
Now, switch to my laptop. I get the above errors again even though I've brought the cert I created over to that machine. The package GUI tells me that there isn't a valid cert to use. I've tried adding that cert to the local machine to no avail.
What am I missing that I should be doing?
My goal is to be able to develop on two different workstations without having to do a dance of creating a new cert everytime I switch one or have to update the csproj file every time I switch from one to the other.
This is a personal project, it's not to the point of going to the store but I do need to dev on two boxes and create side load packages for a set of testers.
Right click the project -> Properties -> Package Manifest
On the Package.appxmanifest go to Packaging tab -> Choose Certificate
In the new window click "Select a Certificate..." if you have one, or create a certificate if you haven't created one
(https://learn.microsoft.com/en-us/windows/uwp/packaging/create-certificate-package-signing)
Source - https://github.com/microsoft/AdaptiveCards/issues/3194#issuecomment-516100011
Unload project.
Edit project file.
Make sure package cert is the same as the one you intend to use.
When i switched to vs 2019 it switched to an old one.
It may old certificate invalid or no Certificate Available, so that we need to create new certificate following way:
Double Click Package.appxmanifest file
Go to the Packaging tab.
the 'Choose Certificate…' button.
Click Create
if Developer Mode is disable kindly enabled
Click OK
Rebuild Project its working fine.
You can try two ways to solve this problem:
Clean solution and restart the visual studio then rebuild the solution.
Delete the test certificate.
Best regards.

Visual Studio project launches at incorrect URL

I have an ASP.NET MVC project in Visual Studio. When running the project, Google Chrome launches but a 'This site can’t be reached' error is shown, and I notice that the https prepended to the URL instead of http. Can anyone advise?
Steps I have taken:
IIS Manager:
Added binding http://mysite.local on Port 80
Set physical path to the project folder root (the same level as the 'App_Data' folder), and set permissions to the IIS_IUSRS group to this folder
Visual Studio:
Server: Local IIS
Project URL: http://mysite.local
Override application root URL: http://mysite.local
Windows Hosts file:
Added entry: 127.0.0.1 mysite.local
Please check whether in your project SSL is enabled or not? You can find it in the properties section of your project like below image:
In Visual studio select the project in solution explorer and set the SSL to false.
Check same in project settings and set the project url to HTTP one there too.
In your MVC Controller :- make sure you didn't apply things like RequireHttps

The Web Application Project [...] is configured to use IIS. The Web server [...] could not be found.

I have a web project in my solution file that is "unavailable" when I open the solution. When I right-click on the web project and reload the project, I get the following error:
The Web Application Project mycompany.myapp.mywebproject is configured to use IIS. The Web Server 'http://localhost/MyWebApp could not be found.
I have not manually set up virtual directories for this web application.
Per colleagues, Visual Studio should prompt me to create virtual directories but I am not getting prompted.
I installed VS2010 before installing IIS on my dev machine.
Here is my development machine setup:
Windows 7 Enterprise
Service Pack 1
64 bit OS
Visual Studio 2010 Enterprise Service pack 1
IIS version 7.5
Since the accepted answer requires IIS Manager, and IIS Express doesn't have IIS Manager or any UI, here's the solution for you IIS Express users (and should work for everyone else too):
When you open Visual Studio and get the error message, right-click the project Solution Explorer and choose "Edit {ProjectName}.csproj"
In the project file, change the following line:
<UseIIS>True</UseIIS>
to
<UseIIS>False</UseIIS>
Save the file.
Now reload your project.
Done.
You'll then be able to open your project. If at this point, you want to use IIS, simply go to your project properties, click the "Web" tab, and select the option to use IIS. There's the button there to "Create Virtual Directory". It may tell you that you need to run Visual Studio as an administrator to create that directory, so do that if needed.
Open the project folder and delete {Project}.csproj.user, then reload the project on Visual Studio.
When this happens the easiest solution is to make the virtual directory manually.
First of all, you need to make sure you have the right version of ASP.Net installed and that you have installed the IIS extensions.
To do this, go to the relevant .net version's folder in C:\(Windows)\Microsoft.NET\Framework\(dotnetver)\
(substituting the bracketed folders for the right folders on your PC) and run this command
aspnet_regiis.exe -i
Next once that's run and finished, sometimes running
iisreset
from the command line helps, sometimes you don't need to.
Next, go to your IIS Manager and find you localhost website and choose add a folder.
Browse to the folder in your project that contains the actual ASP.Net project and add that.
Finally, right click on the folder you added and you should have an option that says 'convert to application' or 'create virtual directory' or something similar.
!!Make sure the Virtual directory has the name 'MyWebApp'!!
Reload your solution and it should work.
Please be wary; this isn't a programming question (and shouldn't really be posted here) but I've posted this guidance as it's a common problem, but the advice I've posted is generic; the commands I've listed are correct but the steps you need to do in IIS may vary, it depends on your version and your account privileges.
Good luck!
This solution worked for me: Right click the Project and select edit and find the following code as shown below in the picture.
change the <UseIIS>True</UseIIS> to <UseIIS>False</UseIIS>
OR
change the <IISUrl>http://example.com/</IISUrl> to <IISUrl>http://localhost/</IISUrl>
For my project, I had to delete these two lines from .csproj file
<ProjectGuid>{3AA499DF-4A65-43B7-8965-D08A4C811834}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
I tried deleting only the first one, but it wasn't enough.
EDIT: As many users have pointed out, this can change your project type or mess with your source control program. I can't investigate these issues as it was a school project I do not have anymore.
Please be careful when trying this. At least make a copy of what you delete.
Edit the .csproj or vbproj file. Find and replace these entries
<UseIIS>true</UseIIS> by <UseIIS>false</UseIIS>
<UseIISExpress>true</UseIISExpress> by <UseIISExpress>false</UseIISExpress>
In my case, this problem was caused by broken IIS bindings. Specifically, my 'http' binding had been deleted. Recreating it fixed the problem.
Cause: The IISURL inside project.csproj is not correctly reflected in the project setting, and the virtual directory was not created.
Solution: Change the Project URL to correct PORT and create the Virtual Directory to make the missing PORT available.
Follow Below Steps:
Step 1: Right click on the project file to Edit the project.csproj file.
Step 2: Search IIS and modify from <UseIIS>True</UseIIS> to <UseIIS>False</UseIIS>
Step 3: Right Click Project to Reload the Project. After Reload successfully, right click Project and select Properties.
Step 4: Locate Project URL option under Properties => Web
Step 5: Change the Project URL to IIS URL indicated both on the Error Message and on the <IISURL>http://localhost:8086 </IISURL> from project.csproj file. Then Click Create Virtual Directory. Save All
Step 6: Redo Step 2 so it doesn't impact the remote codebase and the server deployment settings.
This worked for me:-
Make all your IIS websites point to localhost(All Unassigned) only
Try opening Visual Studio with Administrator privileges. In my case, it gave access to the IIS site and made this error go away. I was then able to switch the project to use IIS Express which doesn't seem to need administrator privileges.
If you are connected via TFS, open your project.csproj.user file and check for
<UseIISExpress>false</UseIISExpress>
and change it to true.
<UseIISExpress>true</UseIISExpress>
You will not believe that, start visual studio as Administrator
as obvious from the message
The Web Server 'http://localhost/MyWebApp' could not be found.
could not be found because may it has no privileges to see it
so Just restart visual studio as Administrator
You can load the project without setting the value of attribute UseIIS to true.
Simply follow the below steps:
In the mywebproject.csproj file--
Delete the tag < IISUrl>http://localhost/MyWebApp/< /IISUrl> and save the file.
The application will automatically assign the default port to it.
In my case I wanted to switch from http to https, so I had deleted http from IIS. In my .csproj.user file found that I still had:
<IISUrl>http://localhost/</IISUrl>
So I changed it to:
<IISUrl>https://localhost/</IISUrl>
In my case I was able to open the solution in offline mode just running the command:
iisreset
For you Win8 users out there, if you follow the steps in the accepted answer, console spits out a message at you saying "thou shalt not use the command-line to execute this command" (paraphrasing). Instead, access the Programs & Features via Control Panel (or Windows + R > appwiz.cpl), click 'Turn Windows features on or off', and make sure you have the following installed:
Internet Information Services
> World Wide Web Services
> Application Development Features
> ASP.NET 4.5
This will check a bunch of other options as well. As soon as I installed these features, and ran VS2012 with elevated permissions, I was able to launch my app successfully.
This happens with me when I tried to open a project from the .csproj file, but I get over it by opening the project from VS:
File> Open> Web Site
and select the directory which include my project.
I had this error, too. I thought everything was setup correctly, but I found out that one thing was missing: The host name I used for my project was not (yet) resolvable.
Since my app determines the current client's name from the host name I used a host name like clientname.mysuperapp.local for development. When I added the development host name to my hosts file, the project was loadable again. Obviously, I had to this anyway, but I haven't thought that VS checks the host name before loading the project.
Check if IIS Express is installed. If IIS Express is missing, Visual Studio might discard the setting <UseIISExpress>false</UseIISExpress> and still look for the express.
in my case, make sure you have a "Default" website
In my case, the "Default Web Site" in IIS didn't have a binding for localhost on port 80.
You should have a binding for whatever your value in the .csproj file is.
I fixed this simply by reinstalling IIS Express after downloading from below link:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=48264
Turns out my IIS was working on localhost:8181.Had to configure the {Project}.csproj file.
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>7386</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>**http://localhost:8181/ProjectName**</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile><EnableWcfTestClientForSVCDefaultValue>True</EnableWcfTestClientForSVCDefaultValue>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
In my case, the url referenced in the csproj file was incorrect.
It needed to be prefixed with www.
I made the changes, saved the file and the project loaded fine.
I ran into this issue when the <ProjectTypeGuids> element in the .csproj file contained the unit test project GUID: {3AC096D0-A1C2-E12C-1390-A8335801FDAB}.
Removing it made the project load without problems.
For DNN users my issue was I needed a binding for dnndev.me at port 80. I have multiple installs that run on different ports and VS requires that that particular Url to exist on port 80 (not 86 like mine was).
Follow this completed solution step by step. it's works for me in VS 2017.
Open Command prompt in administrator mode
Open File explorer and got to .NET Framework folder
Eg:C:\Windows\Microsoft.NET\Framework\v4.0.30319
v4.0.30319 this is my .NET folder. you want to select your relevant folder.
in CMD - Go to .NET folder path
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Execute below command in CMD
aspnet_regiis.exe -i
You can see this message finally - Finished installing ASP.NET (4.0.30319.0)
iisreset
You can see this message finally - Internet services successfully restarted
Open IIS in your computer (if not config Follow this)
Go to Site and right click
Add WebSite
Fill - Site name and select physical path
Then type port number (you can find port number in .csproj file and port number must equal with (IISUrl)
EG : <IISUrl>http://localhost:15724/</IISUrl> my port is 15724
Note : you cannot create port 80 number. because it used default IIS page
Click Ok
Open visual studio with administrator permission
Then right click and reload your project
Your Problem may be solved.
This may help some people in 2020. The main issue is that the IIS settings in the CSPROJ file don't match with the configuration for the machine. For example, if you had the Web Application Project pointing to localhost:12345, and a virtual directory isn't set up on the machine on that port, you'll get this error.
Using VS2019, I had this same issue, and the IIS settings in the CSProj file were being ignored. The reason for this is a new property in the CSProj file called "SaveServerSettingsInUserFile":
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<UserProperties UseAjaxifiedTemplates="True" UseJQuerySupport="True" />
</VisualStudio>
</ProjectExtensions>
When this is set to TRUE, the IIS/Web server properties are in the
.CSPROJ.User file of the same project name.
This allows individual users of a project to have their own IIS settings, provided this file is not checked into source control.
You can control where the settings are stored using Visual Studio GUI in the properties for the project under "Web", "Apply server settings to all users"
When this is on, the IIS settings are stored in CSPROJ, when off, they are stored in CSPROJ.User

Categories