Access IIS Express from Web API from - xamarin.forms

First let me say this used to work in Visual Studio 2015 but I am having the a darn hard time getting it to work in Visual Studio 2017.
I have a WebAPI project running in Visual Studio 2017. I have edited the applicationhost.config file in the …\ProjectName.vs\config file so it has the following entries for my project.
<bindings>
<binding protocol="http" bindingInformation="*:56952:localhost" />
<binding protocol="http" bindingInformation="*:56952:192.168.1.155" />
</bindings>
My firewall is completely disabled. When I try to run my Xamarin forms project on a Win10 Mobile V10.0.15254.0 emulator my app does not connect to the WebAPI. (I get the standard "The text associated with this error code could not be found. A connection with the server could not be established."
If I launch Edge on the emulator and try to access any of my local servers on the network using IP address, that works. Can someone enlighten me with regard to what has changed and how I can now make this work?

So the issue was the IP address I was using. Here are the steps I used to resolved this:
I launched my Windows 10 mobile emulator.
Click on the >> (Tools) icon in the tool bar of the emulator.
Click on the Network tab of the Additional Tools window.
I looked in the list for the network adaptor labeled Desktop Adaptor #1 and copied the IP address.
Edit the Applicationhost.config file in the folder of the WebAPI project.
Find the entry in the file for site name="XXXXX" where XXXXX is the name of the Visual Studio project you are hosting your WebAPIs in.
Within the <bindings> section of the entry for your WebAPI project, add a binding for the IP address you copied from in step 4. It should look something like this:
<binding protocol="http" bindingInformation="*:56952:169.254.69.220" />
Where 56952 is the port my IIS Express is hosting the WebAPIs on and 169.254.69.220 is the IP address I copied from step 4.
After adding this, I was able to connect to locally hosted WebAPIs in IIS Express.
Hope this helps.

Related

Unable to launch the IIS Express Web server. Failed to register URL. Access is denied [duplicate]

What I'm doing:
Opening Visual Studio Community 2015
File -> New -> Project
Under Visual C#: Web -> ASP.NET Web Application
Web Application
And press f5 for the popup error "unable to connect to web server 'IIS Express'."
Deleting applicationhost.config, located in Documents\IISExpress\config, doesn't change the error message. (There's also an IISExpress folder in program files and program files (x86).)
Something I noticed, and I don't know if it's a problem:
Referenced file 'lib/jquery-validation/jquery.validate.js' not found.
I got a dump with rawcap but I don't notice much in there. Some of what was there:
"Framework":{"FrameworkName":"DNXCore,Version=v5.0","FriendlyName":"DNX Core 5.0","ShortName":"dnxcore50","RedistListPath":null}
I don't notice a problem, but I have the network data if that can help figure out why I cannot connect to the web server. I get a RST,ACK immediately so I'm guessing the port is closed and whatever this web server is, isn't being setup.
More on this problem: 800700c1 error from /trace:error
I've tried:
deleting applicationhost.config (and changing port number)
running visual studio as administrator
deleting IISExpress folder in Documents (changes error message until the folder is reinstalled)
toggling ssl off and on, copying url to launch box. (note: I'm not using ssl)
clearing all sfc /scannow errors
starting iisexpress with x86 version and 64-bit version
After installing Update 2 for Visual Studio 2015 I started getting the same error. I tried everything above with no luck. However, I found a solution that works for me:
Delete YourSolutionFolder\\.vs\config\applicationhost.config file (note: .vs is a hidden folder)
Open Visual Studio, right-click on web site > Properties > Debug tab > Web Server Settings > App URL - change port number.
If you have IIS configured to use the same port, (stop the application / use different port) and try again.
Exit VS and delete the (project)\.vs\applicationhost.config file. Restart VS. It should start working.
Try using a different port. I just set up a new Core 1.0 RC1 project and got the same error.
Right click web project
Debug tab
Toggle Enable SSL off and on again, it should generate a new random port
Copy the SSL URL and paste into Launch URL box
Run the project
Worked for me (TM).
Answer from: https://stackoverflow.com/a/28650554/134761
I had this issue on .net core 2.1, visual studio version 15.9.6. When i deleted the .vs folder, i reopened visual studio and the problem was still there. The solution that worked for me below:
Delete .vs folder (it is a hidden folder).
Restart Computer.
Other Solutions:
Close Visual Studio, delete bin and obj folders from the project folder. Open Project then rebuild solution.
Try running Visual Studio as Administrator.
Clean Solution then rebuild
Clean Solution. 2) Exit Visual Studio. 3) delete .vs folder 4) Re-open Visual Studio
Restart machine (if you can afford to)
Copied my comment to an answer by request.
For Net Core 2.2 project - After a MASSIVE struggle and trying everything from deleting .vs folder, deleting IIS Express configs, changing port numbers, changing bindings, and to running VS as admin I FINALLY fixed issue by
closing VS,
deleting launchSettings.json
opening VS which re-generated launchSettings.json.
It was not apparent that the file was corrupt or incorrect or even when it changed to cause failure.
I faced this issue in .net core 2.0 when I update my project's port number.
I was able to sort out issue in two steps :
STEP 1 : DELETE .vs folder which is hidden inside main solution folder. (close visual studio before this) then when you start again visual studio, this folder and file (applicationhost.config) inside it will automatically create by visual studio.
STEP 2 : For multiple startup projects, if you are still facing issue then one by one run project as startup, and then run as multiple startup project.
I had the same issue, i was able to solve it by changing the Port number.
Right click on the project and select properties
Go to the Debug section
Under Web Server Settings change App URL port [just increase by one :)]
In my case that was some other application listening on the same port which IIS Express trying to attach to. I have to run netstat -ao to see PID of process which is use same port and shutdown application. In my case application was Viber.
I just changed my profile from "IIS Express" to "MyProjectName" (which I think is using kestrel as the http server instead of IIS) and now it's working fine:
Run VisualStudio with administrator privilegies and run the project. Then close VisualStudio and all errors and run VisualStudio again with the normal user.
This did it for me.
Looks like that IIS has to write something to some config with admin privilegies (port 80 didn't work with normal user but port 6767 worked fine).
Many of these answered don't fully address the issue at hand. The real problem for me was that I had two bindings using the same port in my applicationhost.config file AND I hadn't opened up the port to my second (non localhost) binding. VS will allow you to still run under these circumstances but only if you are in admin mode (hence all of the answers above).
You are essentially creating two IIS express instances of your app on the same port, so changing one of the ports in your applicationhost.config file will allow you to proceed. There are two different applicationhost.config files however. You will want to select the one that has the binding IP and port that you see in your project's properties
.
Go to the folder where you can see your project solution and project folders (show hidden items in File Explorer). Navigate into your hidden .vs folder -> "YourAppName" folder -> config. It should contain the binding info you saw in your project's properties.
Example:
<bindings>
<binding protocol="http" bindingInformation="*:7000:127.0.0.1" />
<binding protocol="http" bindingInformation="*:7000:192.168.0.5" />
</bindings>
Change one of those port numbers to something other than "7000" so that you aren't trying to use the same port.
In my case, I'm using a 192 address which is not a localhost address, so I need to use some netsh commands to open that port and ip up. Here is a Link that shows how to open up ports for IIS Express to allow remote connection. Running as a normal user will not work unless you run those netsh commands listed.
Here are the netsh commands:
netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone
netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=private remoteip=localsubnet action=allow
Copy those commands and run them in cmd with ADMIN privileges and with YOUR ip address and port number.
TO CLARIFY
Really a lot of answers here are the same and say something like "Restart and it magically works again".
Well, 9 out of 10 times people have this issue like the OP it is because THE IP-ADDRESS IS ALREADY IN USE.
ANSWER
There could be 2 ip-addresses that are in use. Both of them you can find by:
1) Right-clicking on the start-up project
2) Click on "Properties"
3) Click on the "Debug" tab
Here you see your "App URL" and your "SSL URL".
If your "App URL" is in use, just change it there and save it and it should work again.
If your "SSL URL" is in use, close down VS, delete the "applicationhost.config" file in the hidden .vs folder of your project and open VS up again.
The solution that worked for me was to:
Close the VS project
In File Explorer, navigate to the project and delete the entire ".vs" folder
Restart the project
Run as "Debug"
Works
Apparently, it has something to do with the "applicationhost.config" file.
Enjoy!
If you can afford to restart your machine then do it 👌, this fixed my issue after almost an hour of trying to fix this issue with no hope 🤯.
I was able to toggle this error by changing a single thing. In my ASP.Net Core 1.0 RC2 Web Application project's launchSettings.json file:
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:18177/",
"sslPort": 0
}
},
to
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18177/",
"sslPort": 0
}
},
I had changed to https in an attempt to run the project using that protocol. Apparently this is not the place to make that change. I suspect it is creating multiple bindings on the same port, and IIS Express doesn't like that.
I had this same issue, but the way I fixed it was by going to the applicationhost.config and remove a port which was not added by me (IIS Express I would guess) which placed my specific port site on another port.
Here is what the config file had for my bindings:
<bindings>
<binding protocol="http" bindingInformation="*:54764:localhost" />
<binding protocol="https" bindingInformation="*:44360:localhost" />
</bindings>
I removed the first bindings item as the only port I wanted was 44360. My config file now looks like this:
<bindings>
<binding protocol="https" bindingInformation="*:44360:localhost" />
</bindings>
Now I don't see the error when I debug.
I also noticed my second API in my project had port 80 also assigned to it, I removed that as well.
delete bin and obj folders from the project folder and rebuild.
For me the problem was that an other process was using the same port. (In my case it was outlook that was using the same port as my site and thus my site couldn't start)
Yes you can change the local port, but if you are running an API or something that other applications need, you don't always want to do this.
To get a list of what applications are using what port open CMD and type "netstat -aon"
You will get a list of ports. Find the port that your site should use, or that you want to use and write down / remember the PID.
Now open task manager and click on the tab 'details'. Find the process with your PID and end it. Now you should be able to start IIS Express with that port.
I just Cleaned my solution, Then Re-Built it and finally hit F5 and it worked! So simple.
I won't pretend to fully understand what MS bug creates this problem, but here is another potential solution:
In the .vs/config/applicationHost.config file, find the section for <system.applicationHost><applicationPools>. Under the pools, ensure that the managedRuntimeVersion attribute value matches the value which is in the IIS config for the system (and/or the version of the .NET framework which is installed).
For example, you may find (as I did) that the generated file has:
<add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
In my case, you would replace this with:
<add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0.30319" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
Note the replacement from "v4.0" to "v4.0.30319". This resolved the issue.
What appears to be going on:
I believe that VS is generating an applicationHost.config file with "default" versions for the .NET framework, which may not match the specific version which is installed/configured on the system. You can debug/observe this issue by tracing the execution in Process Monitor, and finding the command line for iisexpress.exe. Running this command with /trace:error added yields a more informative message about a failure to preload the CLR with version v4.0. To wit:
Starting IIS Express ...
Failed while trying to preload CLR version v4.0. hr = 80131700
Failed to initalize the W3WP_HOST hr = 80131700
Process Model Shutdown called
Unable to start iisexpress.
Anyway, figured this might be helpful to someone else, since it's common enough to have multiple references online with bad information, and I've personally hit it a few times now.
For me, IIS Express was not accessible when I added iplisten on DOS Prompt like this: netsh http add iplisten MyIPAddress. I fixed it by deleting the iplisten like this: netsh http delete iplisten MyIPAddress.
If you are using VS 2017 or VS 2019 with ASP.Net Core, you can directly go to launchSettings.json under Properties folder and just change the Port number of applicationUrl key for iisSetting.
I just encountered the same problem and I killed all the "iisexpress.exe" processes that were still running. That worked for me!
Try this first if it was working and suddenly stopped:
Close Visual Studio
Kill iisexpress.exe processes
Reopen Visual Studio
Mine happens as soon as I add a new binding inside the applicationhost.config, running as administrator fixed the problem.
Just close the visual studio and reopen and execute.
It worked for me.
My solution (for .net core 2.0) was that i had forgot to add the port number in the applicationUrl, under iisExpress in launchSettings.json
"iisExpress": {
"applicationUrl": "https://localhost:50770",
"sslPort": 50770
}
I was able to resolve this by restarting my computer. I tried a few things unsuccessfully and finally gave up and restarted my computer. It has been working well now for a couple of days after I restarted. Probably the result of some process that was hung.
For me, it was a mixture of following these instructions:
Delete your web application’s .vs\applicationhost.config and try
again.
And then, perhaps most importantly, running Visual Studio with admin privileges.
I added .UseUrls("https://localhost:<some port>/") to the Program.cs. This seemed to do the trick for me!

Running multiple projects on an IIS Express server in JetBrains Rider

I want to run two projects on an IIS Express server using JetBrains Rider.
I've tried using a compound configuration, but I can't find a way to run two projects on the same server? Is that even possible in Rider? In Visual Studio it works, how does Visual studio do this?
Is there any changes I can make to my local .idea applicationhost.config to fix it?
Thanks!
It definitely is possible to run multiple ASP.NET Core IIS Express projects in JetBrains Rider simultaneously. There's a known issue that it requires some additional/manual settings: RIDER-32933. There's a workaround explained in the comments which I'll briefly duplicate here.
IIS Express natively supports running multiple sites using the same configuration file, and Rider uses this ability to some extent. The only issue is that it overwrites IIS config on starting each application, which leads IIS Express to kill any previously started application instance.
From your question, I conclude that you've already created the appropriate run configurations for your apps, so I won't explain it here (but here's a link to the corresponding documentation if you need help).
So, first, you'll need to make Rider to create a proper applicationhost.config for you. To do that, run every configuration you want to run simultaneously at least once. E.g. if you have two apps, "WebApplication1: IIS Express" and "WebApplication13: IIS Express", you'll need to start each of them once.
After you've done that, Rider will generate an appropriate configuration file in .idea/config/applicationhost.config in your solution folder. Important section is:
<sites>
[…]
<site name="WebApplication" id="1">
[…]
<bindings>
<binding protocol="http" bindingInformation="*:49901:localhost" />
<binding protocol="https" bindingInformation="*:44375:localhost" />
</bindings>
</site>
<site name="WebApplication13" id="2">
[…]
<bindings>
<binding protocol="http" bindingInformation="*:26835:localhost" />
<binding protocol="https" bindingInformation="*:44339:localhost" />
</bindings>
</site>
</sites>
So, after you have both of your sites in this config, you'll need to disallow Rider to touch the config. Do that by opening the run configuration settings for both of your configurations and unticking of the Generate applicationhost.config checkbox:
After that, you may either start both of your configurations manually (by selecting each one and pressing the Run button), or using a compound configuration. Debug will work, too.

Debugging ASP.NET cloud project over LAN

I've been trying to debug this ASP.NET cloud project over LAN, because we need it for testing at work. I have done plenty of research on the subject, but I simply cannot get it to work as expected. I think I have narrowed the problem down to being that, the project is a cloud service project.
If I create a new ASP.NET MVC project, without the cloud service, it works just fine, when editing the projects bindings, plus turning off the firewall of course. If I then do the same procedure, but with a cloud service project, with the asp.net mvc as the web role, I get "connection refused" when trying to access it over LAN.
Does anyone have any idea what's going on and/or how to solve it?
Bindings:
<bindings>
<binding protocol="http" bindingInformation="*:5807:localhost" />
<binding protocol="http" bindingInformation="*:5807:*" />
</bindings>
I spent almost a full day at work with exactly the same issue.
It finally started to work after I reïnstalled IIS express.
Uninstall at Programs and Features
Download the Microsoft Web Platform Installer found at link below:
http://www.microsoft.com/web/downloads/platform.aspx
search for IIS express, and install it.
After that, it worked like a charm for me. I hope it works for you as well, because I wasted way too much time on this problem...

VS2012 ASP.Net error message unable to connect to the configured development web server

I bought a new Windows 8 PC last week.
First I installed VS 2010 on it but then that wasn't working properly so I uninstalled VS 2010 and then installed VS 2012 professional edition and SQL Server 2012.
Now I am able to create Windows applications but I am not able to run even a simple ASP.Net website.
When I try to view Default.aspx in browser it throws an error message that
Unable to connect to the configured development web server
so then I went into Add or remove components and installed IIS. but I still get that error message.
Even if I try to save the website at a folder location, the ASP.Net development server is not able to run the web page.
I get the same error message using either IIS or ASP.Net development server.
I am wondering is it Windows 8 security related issue?
How can I make sure my ASP.net Development server was installed correctly and has the appropriate permissions to run?
Does ASP.net work with regular Windows 8? or do I need Windows 8 pro? Microsoft's website doesn't say anything about it so am assuming Windows 8 should work because the Windows forms application works.
Please advise. I just want to be able to run a simple ASP.Net application to verify the installation.
I tried http://forums.asp.net/t/1768992.aspx/1 but that didn't work in this case.
ASP.NET IIS Registration Tool (Aspnet_regiis.exe) would be one of my suggestions along with checking what identity is the Application Pool in IIS using as it may have limited permissions. Last but not least, run Visual Studio as an Administrator so you don't have UAC issues.
All right. I had this problem for a week and I have tried many solutions. Finally, the following procedure will fix the problem.
I have set the Firewall system manually. This means that, at the time of communication by programs Firewall notify me. Incorrectly linked to "devenv.exe" was blocked by the Firewall. Correct mode of communication "devenv.exe" will solve the problem. "devenv.exe" is located in the following path.
"C: \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Common7 \
IDE \ devenv.exe"
Devenv lets you set various options for the integrated development environment (IDE), and also build, debug, and deploy projects, from the command line.
Enjoy...
I've run into the same general error message that you stated, but the details of my error included the following:
Unable to connect to the configured development Web server.
Failed to register URL “http://10.10.7.209:53553/“ for site
“FooBarSite” application “/“. Error description: The format of the
specified network name is invalid. (0x800704be)
The fix for me was to make changes to the applicationhost.config file located in C:\Users\Jed\Documents\IISExpress\config
Specifically, I had to update the bindingInformation for the site so that the IP Address matched the IP Address of my development computer.
Instructions
Run ipconfig to determine the IP Address of your computer
Open C:\Users\Jed\Documents\IISExpress\config\applicationhost.config (in Notepad)
Scroll down to <sites>, then find the <site> that has the name of your project (in this example it was FooBarSite
Update the bindingInformation so the IP Address matches the IP Address that was determined in ipconfig
Example
<bindings>
<binding protocol="http" bindingInformation="*:53553:localhost" />
<binding protocol="http" bindingInformation="*:53553:10.10.7.209" />
<!-- I had to change the IP Address from 10.10.7.209 to 10.10.7.214 -->
</bindings>

Setting up IIS Express to accept local connections on visual studio 2012

I made a web service with MVC4 and running on localhost with IIS express seems fine.
But I need to access from outside, so I'll have to use a local IP.
I've found out that IIS Express only accepts incoming requests with localhost specification in the header.
I've tried to go to the "applicationhost.config" and change the
binding protocol="http" bindingInformation="*:4019:localhost"
to this:
binding protocol="http" bindingInformation="*:4019:10.250.38.85"
but now visual studio wont let me run IIS Express saying its unable to launch.
I've also been wandering around IIS manager trying to attach one of the websites to the project without success.
What am I forgetting?
I'll also need this to use SSL and not sure how to configure
I've tried to edit IIS Express applicationhost.config and change binding protocol="http" to https but then vs2012 couldnt even load the project saying it couldnt create the virtual directory
Is there a way to change IIS express to normal IIS 7 so I can use the manager?
You can assign IP in the iis as follows:
Then you need to publish your website into this iis website. it will work....

Resources