VS 2015: Binding a WebApp to something besides localhost - asp.net

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.

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.

IIS Express http/https bindings not working correctly

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.

VS 2013 / IIS Express - serve site from localhost:port/myapp instead of localhost:port

In prod my site (mvc5) is hosted on https://company.no/myApp/ where myApp is an Application on IIS.
In dev my site is hosted on IIS Express on http://localhost:54307/
As this causes some truble with server relative paths I would like to also do my debugging on http://localhost:54307/myApp.
This is what I've tried:
Setting project url in property pages to http://localhost:54307/myApp and clicking Create Virtual directory
Tried the override application root with or without the myApp url.
Tried modify the applicationhost.config. Currently my setting looks like this:
<site name="MyApp.Web-Site" id="38">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\OP\MyApp\Main\src\MyApp.Web" />
</application>
<application path="/MyApp" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\OP\MyApp\Main\src\MyApp.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54307:localhost" />
<binding protocol="https" bindingInformation="*:44307:localhost" />
</bindings>
</site>
When I try to open page from the myApp folder I get the follownig error:
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x800700b7
Config Error Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'WSFederationAuthenticationModule'
Config File \\?\C:\Projects\OP\MyApp\Main\src\MyApp.Web\web.config
Requested URL http://localhost:54307/MyApp
Physical Path C:\Projects\OP\MyApp\Main\src\MyApp.Web
That indicates web.config loaded twice. Any idea what I'm doing wrong?
Thanks for any help
Larsi
I hear you with IIS Express causing problems with server relative paths. You can set this up with a couple steps that don't include manually editing your applicationhost.config. I try to avoid editing the applicationhost.config manually, it seems to cause more problems than it solves. I would remove the website from your local IIS to clear out any of that stuff and then do the steps below:
right-click on your web project and select properties.
Click on the "Web" menu
change the dropdown to Local IIS and enter the URL you would like the app to resolve to then click create virtual directory, save the file and build.
You can still debug without the port number, the debugger will just attach to this new website in your local IIS instance as long as you have a debugger option checked on the web tab.
open your local IIS and make any other configurations that are required for your app to run (Authentication, Application Pools, etc.).
open your browser and navigate to http://localhost/YourAppName
since this is a website as far as your local iis is concerned, you can hit it anytime in a browser without needed Visual Studio running.

Visual Studio 2012 Launches Wrong Project For Debugging

I've got an ASP.NET web application project in a Visual Studio 2012 solution. I'll refer to this as A.
I copied A's directory to a new directory to make a clone of it. I'll refer to this as B.
I made extensive changes to both A and B to the point that they are not even remotely similar. Stylesheets, scripts, HTML, and back end is all different.
I launched A for debugging, and it appeared in my browser as expected. I debugged the application for awhile, and then terminated debugging via the "stop debugging" icon on the toolbar within Visual Studio 2012.
I then launched B for debugging. Instead, I got A.
I tried clearing browser cache, though, this couldn't be the problem because the server side of the application was wrong too.
I tried Rebuilding the project, after running Clean. I still see A while trying to debug B.
I tried killing all processes related to the debugging session including all iisexpress.exe, MSBuild.exe, WebDev.WebServer40.EXE, Microsoft.VisualStudio.Web.Host.exe instances.
I tried closing Visual Studio 2012 completely, reopening it, and retrying debugging.
EDIT
After closing and reopening VS2012 for a third time, it started now allowing me to see B. Nothing else has changed.
Best I can come up with is there must be some type of project setting that needs to be changed to reflect that the project lives in a different space than it did before being copied, but I have yet to track down such a setting.
What am I missing?
I have just come across this issue today, having done exactly as you (copied a project, and then edited). And hence i would like to share my solution.
If you go to Project B's Properties (found in solution Explorer), you will find a Web tab:
In your Servers section, alter the Project Url to:
http://localhost: + (number +1) + /
and then hit Create Virtual Directory
You should then be able to re-run your project and since they're running off different Url's, you shouldn't see this clash again.
I was in the exact same situation. The problem was that both projects (Project_A & Project_B) we’re setup to run on the same port in IIS Express.
IISExpress determines the port/application by looking at a configuration file located in <Documents>\IISExpress\config\application.config.
Open that file and look for a section <sites>. You should find a list of your VS projects. Locate your projects (A and B) and make sure that both projects are not running on the same port
<site name="Project_A" id="17">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\Somefolder\ Project_A " />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:64212:localhost" />
</bindings>
</site>
<site name="Project_B" id="18">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\Somefolder\ Project_B " />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:64212:localhost" />
</bindings>
</site>
If that is the case, remove one entry (i.e. Project_B), and then go in Visual Studio to recreate the entry.
In VS, go in the Properties of Project_B. Click on Web tab and look for the “Servers” section.
Enter a new port (i.e. `http://localhost:64213`) and click on the “Create Virtual Directory” button. This will add an entry in the “application.config” file, with the new association (i.e. Project_B / port 64213)
This should fix the problem. Hope this helps
This question is not marked as answered and as I had a similar problem I thought I would answer it.
you need to go to project > properties > web then check the use local web server box and overide application root if applicable, change the path names to the ones you are using save and it should work.

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