IIS Express http/https bindings not working correctly - asp.net

I have a solution with 6 projects in it. And for 2 of them I enabled SSL in project properties.
The problem is, that when I start debugging, all my projects starts with https, even if they're not configured to use SSL.
E.g. before enabling SSL my project was accessible via http://localhost:63684/. Now, with https enabled I can access my project under https://localhost:43000/, but when I try to access this url: http://localhost:63684/, it automatically changes to https://localhost:63684/ and I get the following error in the browser:
SSL connection error
ERR_SSL_PROTOCOL_ERROR
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
The same goes for the projects, which doesn't have SSL enabled and I can't access them.
...\Documents\IISExpress\config\applicationhost.config file has proper bindings:
<bindings>
<binding protocol="http" bindingInformation="*:63684:localhost" />
<binding protocol="https" bindingInformation="*:44300:localhost" />
</bindings>
And other 4 projects, which doesn't have SSL enabled, but are still automatically switched to https:
<bindings>
<binding protocol="http" bindingInformation="*:11483:localhost" />
</bindings>
I already tried to delete IISExpress folder, because I thought config is broken somehow, but it didn't help.
Any ideas what causes automatically switching to https and how to fix it?
BTW, I was following this article when implementing https in my 2 projects and my goal is to be able to use http when debugging locally and https when project is published to the web.

Turns out, that it was a Chrome problem, because I noticed, that on other browsers everything is working well. This SO answer helped me to fix this issue.

Related

ERR_SSL_PROTOCOL_ERROR for localhost from Visual Studio debug

I am running a simple ASP.net web application. Chrome is showing the below error after running this.
localhost sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
but my application is on http, not https.
but the URL is loading with https://localhost:54056/
config is also pointing to http only.
<site name="tan-square" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\Myfolder\OneDrive\Downloads\tan-square" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54056:localhost" />
</bindings>
</site>
I don't understand where the problem is. Why is it loading with https?
First, check your site web binding detail by the following detail:
Open visual studio, select your project.
right-click on the project and select properties.
under the Web tab and check your project url.
make sure there no such setting in your web.conifg file like below:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security"
value="max-age=16070400; includeSubDomains" />
</customHeaders>
</httpProtocol>
</system.webServer>
When the browser sees this, it will remember, for the given number of seconds, that the current domain should only be contacted over HTTPS. In the future, if the user types http:// or omits the scheme, HTTPS is the default.
Clear your browser cache.
Another thing you could try to find the cause is open chrome and type chrome://net-internals/#hsts in the address bar and search for localhost:
The query shows “localhost” as being in the list of domains in the HSTS set.
The solution is deleting the domain from the cache. type “localhost” into the Delete domain text field, and hit Delete. After doing that when you query for “localhost” again you will receive a “Not found”.
Just create new Virtual Directory:
1-right-click on the project and select properties.
2-under the Web tab change your project url by changing the localhost to http://localhost:48333/ .
3- click Create Virtual Directory.
4- make sure you don't have this in web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=16070400; includeSubDomains"/>
</customHeaders>
</httpProtocol>
</system.webServer>
If you are running .net core, just run Visual Studio as admin, or go to bin\Debug\netcoreapp3.1 directory, and issue. Wierdly, .net core. .net core surprisingly dont give any error.
%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-3.1.exe --port 5059
change port number to whatever.
Go to launch settings
change the launch URL to https instead of http,
it will ask you to add self generated ssl ,
click Yes and it Run the project.
Hope this will help you
In my case "clearing SSL State" has solved my issue.
Open the Start menu.
Search for and open Internet Options.
In the dialog box that appears, select the Content tab.
Click Clear SSL State.
Change default browser to Chrome and the issue is solved.

VS 2015: Binding a WebApp to something besides localhost

I've got an VS WebApp I am testing (An OData Provider if it matters). The client is Android.
You can't run the server and client (via a simulator of the client' OS) on the same box.
So I'm using a physical Android device to run the client. Unfortunately Visual Studio is hell bent on binding the webapp to (and only to) localhost. It isn't won't respond to attempts to connect to the hostname or IP address, and any attempt to change the IIS configuration inside of Visual Studio meets with an error message saying you specifically must use localhost (which obviously cannot be used to connect to from a another machine)
1) How do I get around this?
and
2) If this isn't obvious to find, how are people are expected to test from a remote device on their development machine?
JoeHz,
You need to change the binding configuration of your IIS Express for your WebApp.
In the folder where your *.sln is, find the hidden folder named .vs. Then open the xml file applicationhost.config in the config folder.
In the applicationhost.config file, find the sites nodes, then the site you want to configure.
For example:
<site name="MySiteName" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\MyDirecctory" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8381:localhost" />
<!--Add new binding here with ip address-->
<binding protocol="http" bindingInformation="*:8381:192.168.0.10" />
<!--or add new binding with machine name-->
<binding protocol="http" bindingInformation="*:8381:MachineName" />
</bindings>
</site>
Once the file saved, make sure your IIS Express is closed and start your website. Once IIS Express started, check if the new binding worked, you should see something like this:
Ensure you can access the website in your web browser, not with localhost, but this time with your new binding like http://192.168.0.56:33617.
If all is good, then go to your Firewall, and add a new TCP rule for the port you need to open
When done, at that point any device on the same network should be able to access the website. Try the new address on your Android device web browser.
Your Android client should now be able to access your WebApp.

IIS Application Initialization not Firing into ASP.NET Application

Running on Windows 8, I have enabled the Application Initialization feature of IIS from the Windows Features install options for IIS.
I'm attempting to get an ASP.NET Web app to start up immediately and fire into Application_Start when the Application Pool is restarted. I've followed the instructions from this tutorial, but after setting the values in the ApplicationHost.config, and web.config I see nothing is firing.
Here's what I've set (which seems to match what the article suggests):
<applicationPools>
<add name="MPress" autoStart="true"
enable32BitAppOnWin64="true"
startMode="AlwaysRunning">
<processModel identityType="LocalSystem" setProfileEnvironment="true" />
</applicationPools>
<sites>
<site>
<application path="/MPress.Workflow.WebQueueMessageManager"
applicationPool="MPress" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="C:\Projects2010\Clients\MPress\MarvelPress.Workflow.WebQueueMessageManager" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
</sites>
And then in the local web.config I have:
<system.webServer>
<applicationInitialization remapManagedRequestsTo="Startup.htm"
skipManagedModules="true"
doAppInitAfterRestart="true">
<add initializationPage="default.aspx" />
</applicationInitialization>
</system.webServer>
Other than the doAppInitAfterRestart flag this matches the settings in the above article exactly except pointing at my virtual app and application pool.
It appears that the Application Pool auto load works - if I stop and restart IIS w3wp I see the application pool show in the task list. But using Process Explorer I can see that the EXE hasn't loaded .NET just sitting there. No .NET Runtime dlls are loaded, so it appears that no request has fired.
What really sucks is that there's no real documentation of section and expected values required for each setting. The doAppInitAfterRestart flag is documented nowhere that I could find. I've also left that out with the same results. I'm also not 100% what the syntax for the URL is. The MSDN article points at "/default.aspx" and I tried that too to no avail.
I also turned on Failed Request Tracing in IIS to see if maybe the fake request fails somehow, but nothing shows up in there. It simply looks like Site Level load is not firing when the application pool restarted.
All of the settings mentioned here are also available through the IIS Admin UI in Windows 8 and everything certainly looks correct.
I'm out of ideas on what else to check or what I might be missing. Any ideas appreciated.
After some more spelunking it turns out that although I had installed the Application Initialization feature using the Windows 8 features, the actual module was not added to the globalModules list.
The following was missing and once added everything started working just fine:
<globalModules>
<add name="ApplicationInitializationModule" image="%windir%\System32\inetsrv\warmup.dll" />
</globalModules>
I faced similar issue but after doing a bit of comparison I found that you need to set Application Pool Managed Pipeline Mode to Integrated. It will not work with Classic Mode

Unable to disable SSL for website

I created a website and deployed it to Windows Azure. Somewhere during development I enabled SSL from the project properties and everything (https address) was working fine in localhost and on the Azure website where I deployed my site.
Now my Azure trial is expiring and I am moving my website to another free asp.net hosting that does not support SSL without paying for it.
So I'm thinking it is going to be easy, just set SSL Enabled back to False as it was when I first started development and everything is fine, but that is not the case.
My website refuses to work after I disabled SSL.
Picture of my Visual Studio setting with IIS Express opened and showing that there is a server on the right address: http://db.tt/EKTcxPsd
When I launch the site from Visual Studio it starts loading the page localhost:44300.
After a few seconds I am redirected to https://localhost that displays a "webpage is not available" error. Picture: http://db.tt/VntZTpKD
I have tried deleting the IISExpress folder and relaunching visual studio. The recreated applicationhost.config file has the correct information (as far as I know)
<site name="PrototypeNew-bootstrap3" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\path-shortened\Visual Studio 2013\Projects\PrototypeNew\PrototypeNew-branch" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:44300:localhost" />
</bindings>
</site>
I have the same problem after publishing the website to a hosting environment.
Going to http://mywebsite.com redirects me to https://mywebsite.com and shows the same error as the localhost page.
If I re-enable SSL then the https address on my localhost starts working fine.
Does anyone know what is going on here? Is there another SSL switch somewhere that I forgot to turn off? Why is it always redirecting me to https
EDIT. Tried creating a new asp.net mvc 4 project. Launched it and it was working fine. Copied the web.config to my project and it was still redirecting to https:localhost
Okay I finally found the solution. FilterConfig.cs looked like the following:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new System.Web.Mvc.AuthorizeAttribute());
filters.Add(new RequireHttpsAttribute()); // problem
}
It must have automatically added the RequireHttpsAttribute when I enabled SSL and then didn't remove it. Removing it manually fixed the problem.

Binding IIS Express to an IP Address [duplicate]

This question already has answers here:
How to enable external request in IIS Express?
(27 answers)
Closed 7 years ago.
Is it possible to use IIS Express to host pages on a network. Out of the box it can do localhost but I am trying to bind it to an IP address.
I think you can.
To do this you need to edit applicationhost.config file manually (edit bindingInformation '<ip-address>:<port>:<host-name>')
To start iisexpress, you need administrator privileges
In order for IIS Express answer on any IP address, just leave the address blank, i.e:
bindingInformation=":8080:"
Don't forget to restart the IIS express before the changes can take place.
As mentioned above, edit the application host.config. An easy way to find this is run your site in VS using IIS Express. Right click the systray icon, show all applications. Choose your site, and then click on the config link at the bottom to open it.
I'd suggest adding another binding entry, and leave the initial localhost one there. This additional binding will appear in the IIS Express systray as a separate application under the site.
To avoid having to run VS as admin (lots of good reasons not to run as admin), add a netsh rule as follows (obviously replacing the IP and port with your values) - you'll need an admin cmd.exe for this, it only needs to be run once:
netsh http add urlacl url=http://192.168.1.121:51652/ user=\Everyone
netsh can add rules like url=http://+:51652/ but I failed to get this to place nicely with IIS Express. You can use netsh http show urlacl to list existing rules, and they can be deleted with netsh http delete urlacl url=blah.
Further info: http://msdn.microsoft.com/en-us/library/ms733768.aspx
Below are the complete changes I needed to make to run my x64 bit IIS application using IIS Express, so that it was accessible to a remote host:
iisexpress /config:"C:\Users\test-user\Documents\IISExpress\config\applicationhost.config" /site:MyWebSite
Starting IIS Express ...
Successfully registered URL "http://192.168.2.133:8080/" for site "MyWebSite" application "/"
Registration completed for site "MyWebSite"
IIS Express is running.
Enter 'Q' to stop IIS Express
The configuration file (applicationhost.config) had a section added as follows:
<sites>
<site name="MyWebsite" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\build\trunk\MyWebsite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:192.168.2.133" />
</bindings>
</site>
The 64 bit version of the .NET framework can be enabled as follows:
<globalModules>
<!--
<add name="ManagedEngine" image="%windir%\Microsoft.NET\Framework\v2.0.50727\webengine.dll" preCondition="integratedMode,runtimeVersionv2.0,bitness32" />
<add name="ManagedEngineV4.0_32bit" image="%windir%\Microsoft.NET\Framework\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness32" />
-->
<add name="ManagedEngine64" image="%windir%\Microsoft.NET\Framework64\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness64" />
Change bindingInformation=":8080:"
And remember to turn off the firewall for IISExpress

Resources