IIS Express URL binding is not bound as configured? - asp.net-mvc

I have 2 bindings for my app configured in the applicationhost.config like this:
<bindings>
<binding protocol="http" bindingInformation="*:12692:localhost" />
<binding protocol="http" bindingInformation="*:80:127.0.0.2" />
</bindings>
As you can see there is one IP binding there, at first there is no ACL setup to allow it so I have to run the VS as admin so that the binding can be done OK (otherwise the app won't run). If I run it as admin I can see the 2 bindings configured OK (they are shown in the IIS Express window accessible from the system tray icon).
Now I want it more convenient (not requiring administrative privilege) by adding the IP (for the second binding) to the ACL by using netsh like this:
netsh http add urlacl url=http://127.0.0.2:80/ user=everyone
It reported OK, then I could try reopening the project normally (not as admin) and the app run OK (not any binding error reported) but I could see just one binding (the second binding), the first binding is not configured as expected. Now if I try running the VS as admin again, it still works fine with 2 bindings configured correctly.
So looks like it's just a problem of running VS as admin or not (the ACL configuration is not involved). How could that cause the issue?

it is not a recommended way to modify the applicationhost.config file. another thing is when you open a visual studio you can only see the one site bing in the application property. if you want to use more than two bindings with a site you could use the iis or iisexpress command:
run command prompt as administrator.
enter the iisexpress.exe folder path by running below command:
cd C:\Program Files\IIS Express
then run below command to run iisexpress site:
iisexpress /config:C:\Users\Administrator\source\repos\webformtest1\.vs\webformtest1\config\applicationhost.config /site:webformtest1(3)
in this way you can see both the binding in iis express tray:

Related

Remote Access to Local ASP.NET Core Applications From IP Address?

I want to (call)debug my asp.net core application from remote computer or mobile device? please help me. In standard .net add this code in .vs\config\applicationhost.config when change <binding protocol="http" bindingInformation="*:21918:localhost" /> to <binding protocol="http" bindingInformation="*:21918:*" /> its worked.
<site name="project" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\users\Api" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:21918:*" />
</bindings>
</site>
You can use this method:
Open Program.cs in your project:
var configuration = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var hostUrl = configuration["hosturl"]; // add this line
if (string.IsNullOrEmpty(hostUrl)) // add this line
hostUrl = "http://0.0.0.0:5001"; // add this line
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls(hostUrl) // // add this line
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseConfiguration(configuration)
.Build();
host.Run();
More Info
There is a tunneling solution for this situation, you can use ngrok app to tunnel you local env and give a remote URL to the outside of the network for debugging or testing purpose.
After downloading ngrok just run this command:
./ngrok http 25114 -host-header="localhost:25114"
Don't forget to replace your local app port.
you can follow the instructions below on how to solve your problem and go through all these problems.
1- Be sure you don’t ave any open Visual Studio instance.
2- Open the file %userprofile%\Documenti\IISExpress\config\applicationhost.config , being %userprofile% your user folder – like C:\Users\YourUsername\.
3-Look for the entry corresponding to the web application we want to modify and change its binding element in the following way:
<binding protocol="http" bindingInformation="*:<port>:*" /> All we need to do there is to replace a couple of localhost with *, leaving the automatically assigned <port> as it is. If you really need to change that port, replace it with another valid, free TCP port (like 8080) and perform the following step. Otherwise, skip it and go to the step next to it.
4-If you changed the automatically assigned TCP port you also need to open your web application project (.csproj) and solution (.sln) files and ensure there are no references to the previous port: they can be there or not depending on your choosen project type (Web Application, MVC App, Web Site, etc.). If that’s the case, replace the old port with the new one.
5-Open a Command Prompt (with Administrator permissions) and type the following:
netsh http add urlacl url=http://*:<port>/ user=everyone Putting the application TCP port in place of . If you get an error messae (1789) it means that the Everyone user group is not present on your system, something who can occur in some Windows localizations. If that’s the case, just replace everyone with the corresponding user group name. Instead than doing this step you could also try and execute Visual Studio with administrator permissions.
6-Open Windows Firewall advanced configuration panel and add an inbound rule to enable the inbound traffic for the application IISExpress.exe OR for the TCP port used by your web application. If you disabled it for another product, do the same with it. If you ain’t using any – are you sure? – you can either take the chance to fill the void and then perform the above or just skip this step.
Once you did this you can launch Visual Studio and run your application in Debug or Release mode: you should be able to access it from any external, network-connected device using the following web address:
http://<lan-ip-address>:<port>/
For .net core its very simple to access to your local web app running on VS from a remote device; just change applicationUrl values in launchsettings.json from "https://localhost:[port]" to "https://0.0.0.0:[port]" and similar for http binding.
If you have a firewall running on host machine, you might need to allow the port for remote access.

ASP .NET Core 2.0 Change "localhost" to a "hostname"

I have a Web App written based on MVC framework. It runs really well on the localhost and default port 51290. Now I need to run it using my domain name e.g. myhostname. What I have tried is to add a line in "applicationhost.config" section:
<binding protocol="http" bindingInformation="*:80:myhostname" />
When I press Ctr+F5, I got an error msg saying port 80 is in use.
The server is IIS express.
Can someone please instruct how should I run this App using host name? Thanks.
After I run visual studio as admin, everything worked!
Win+R to open the Run dialog.and type "drivers"
now you can see "etc" folder,inside that there is a file named as "hosts".open that and change local host name to your domain name.
http://www.c-sharpcorner.com/UploadFile/8d44fb/how-to-access-the-site-using-domain-name-instead-of-localhos/

Visual Studio 2017 - Giving remote users access to website in IIS Express

Been looking through and trying all guides i found on this topic but no luck. I am running and MVC project with HTTPS and want to access the debug site with some remote mobile devices to test out the website. I followed a guide that almost work and i think I am pretty close to getting it to work. Here are the steps I have done:
Turn off Firewall
Open projectfolder of website go to \vs\config\ and open applicationhost.config
Find your site and line that contains your mapped port like this:
-edit it to get this result:
Tried to run Visual Studio as Admin at this point, Got regular error 400: Bad Request - Invalid Hostname when trying to access site from other computer
Opened CMD as Admin and ran the following command:
netsh http add urlacl url=http://*:44363/ user=everyone
- URL reservation successfully added
-Tried to start Visual studio as admin and non admin. Gets the following error message
"Unable to launch the IIS Express Web Server.
Failed to reister URL "https://localhost:44363" for site "x" Application. Error description: Cannot create file when that file already exists"
-I then have to run cmd again and remove the url with the command:
netsh http delete urlacl url=http://*:44363/
How do i get this to work with Visual Studio 2017 ? I cant be many steps from getting it to work. I have read many guides but none of them works
Amazing how such a simple common need can be so painful to fulfill out of the box in 2017!
Anyway https://github.com/icflorescu/iisexpress-proxy worked nicely for me.
Install it with node:
npm install -g iisexpress-proxy
Then its just something like:
iisexpress-proxy 51123 to 3000
Under 2 mins to get running.
Let me share my experience with Visual Studio and IIS Express that should help you. I am not using HTTPS and my project type is Web site with WCF but you should be able to accomplish your goal.
Here are prerequisites:
IIS Express installed
Visual Studio installed
Added url reservation for public port (netsh http add url=http://*:50001/ User=Everyone) from elevated command prompt.
Added firewall inbound rule for 50001 TCP port (Control Panel-->Windows Firewall-->Advances Settings-->Inbound Rules-->New Rule...)
Now let us setup a project in VS. I am using one of predefined templates with C#. Compile it and try to run it from VS. At that moment VS is starting developer instance of IISExpress that helps your site to run.
You should be able to see IIS Express icon in Notification area. With right click you will see that your site is running and a port (we will call it VSPORT) that is assigned by VS. This port must be different than reserved port (50001).
If you managed to accomplish this without problems then you have almost everything ready for running your site without VS.
Go to your project folder
Go to .vs folder
Go to config folder
Open applicationhost.config
Locate sites/your_site section
Copy everything between your_site and /your_site
Now we need to add this info in "global" IIS Express config.
Go to IIS Express folder (something like c:\Users\USERNAME\Documents\IISExpress)
Go to config folder
Open applicationhost.config
Locate sites section.
Paste information about your site.
Change binding from
binding protocol="http" bindingInformation="*:VSPORT:localhost"
to
binding protocol="http" bindingInformation=":50001:"
Save changes
With this change you may start IISExpress.exe directly and you can continue to use VS to work on you project at the same time.
If you want to access it from other computers do it as http://YOURIP:50001/.
Do have in mind that you need to ensure that your javascript code is NOT using address and port number directly.
You can solve the problem by downloading the 'conveyor' library from extensions and update in Visual Studio.
You can access it from other devices.
Open Visual Studio
Tools > Extensions and Updates
Online > Visual Studio Marketplace
Search 'Conveyor'
Download and install this extension
When you launch the API, you can access it from other devices. This plugin creates a link from your own ip address.
Example:
https://youripadress:5000/api/values

HTTP Error 500.19 and error code : 0x80070021

I have a simple webAPI build by Visual Studio 2013. It works well when I run it from VS13 but when I copy the project in local IIS it gives me the following error.
HTTP Error 500.19 - Internal Server Error The requested page cannot be
accessed because the related configuration data for the page is
invalid.
Detailed Error Information:
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070021
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File \?\C:\inetpub\wwwroot\APITeslin\web.config
Config Source:
36: <system.webServer>
37: <handlers>
38: <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
Got precisely the same error and came to this question. As #SpaceBison mentioned in comments, this answer describes the solution - https://stackoverflow.com/a/12867753/404099. I spotted it too late and it misses some steps. This is what worked for me:
Windows Server 2012, IIS 8.5. Should work for other versions too.
Go to server manager, click add roles and features
In the roles section choose: Web Server
Under Security sub-section choose everything (I excluded digest, IP restrictions and URL authorization as we don't use them)
Under Application Development choose .NET Extensibility 4.5, ASP.NET 4.5 and both ISAPI entries
In the features section choose: NET 3.5, .NET 4.5, ASP.NET 4.5
In the web server section choose: Web Server (all), Management Tools (IIS Management Console and Management Service), Windows Authentication - if you are using any of it
I got this error while trying to host a WCF service in an empty ASP.NET application. The whole solution was using .NET 4.5 platform, on IIS 8.5 running on Windows 8.1.
The gotcha was to
Open up "Turn Windows Features on or off"
Go to WCF section under ASP.NET 4.5 advanced services
Check HTTP Activation.
You'll be asked to restart the system.
This should Fix the HTTP 500.19!
EDIT 11-FEB-2016 Just got an issue on Windows 10 Pro, IIS 10, This time, it was an HTTP 404.0. The fix is still the same, turn on "HTTP Activation" under Windows Features -> .NET Framework 4.6 Advanced Services -> WCF Services -> HTTP Activation
I also was getting the same problem but after brain storming with IIS and google for many hours. I found out the solution.
This error is because some settings are disabled in IIS applicationHost.config.
Below are the steps to solution:
Go to C:\Windows\System32\inetsrv\config\applicationHost.config and open in notepad
Change the following key value present in
<section name="handlers" overrideModeDefault="Deny" /> change this value from "Deny" to "Allow"
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
change this value from "Deny" to "Allow"
It worked for me.
If you're running IIS on that computer for the first time, you should try running the ASP.NET IIS registration tool (aspnet_regiis.exe).
Here's how to do that:
If you're using .net framework v4, open command prompt as an administrator, and change directory to your .net framework base folder using:
CD C:\Windows\Microsoft.NET\Framework\v4.0.30319
or, if you're using a 64 bit computer, use:
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
when you've successfully navigated to the appropriate directory, execute the ASP.NET IIS registration tool using:
aspnet_regiis -i
If you're using a different .NET framework version, simply replace v4.0.30319 with the appropriate folder name.
Hope this helps.
I solved this by doing the following:
WebServer(ISS)->WebServer->Application Development
add .NET Extensibility 3.5
add .NET Extensibility 4.5
add ASP.NET 4.5
add ISAPI Extensions
add ISAPI Filters
On Windows 8.1, IIS 8.5 the solution for me was to register 4.5 from the control panel:
Programs and Features > Turn Windows features on or off > Information Information Services > World Wide Web Services > Application Development Features > Select ASP.NET 4.5
Click OK.
As the error idnicates - "This happens when the section is locked at a parent level". To unlock the section you can use appcmd.exe and execute the following command:
%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers -commitpath:apphost
For more information on about section locking and what a parent configuration context is refer to IIS documentation.
If it is windows 10 then open the powershell as admin and run the following command:
dism /online /enable-feature /all /featurename:IIS-ASPNET45
On Windows 8.1 or 10 include the .Net framework 4.5 or above as shown below
In our case, we struggled with this error for quite some days. It turns out that in control panel, programs, turn windows features on or off.
We selected Internet Information Services, world wide web services, Application development features and there we check the set of features associated with our development environment. For example: ASP.NET 4.6. .NET Extensibility 4.6, etc.
It works!
Try unlocking the relevant IIS (7.5) configuration settings at server level, as follows:
Open IIS Manager
Select the server in the Connections pane
Open Configuration Editor in the main pane
In the Sections drop down, select the section to unlock, e.g. system.webServer > defaultPath
Click Unlock Attribute in the right pane
Repeat for any other settings which you need to unlock
Restart IIS (optional) - Select the server in the Conncetions pane, click Restart in the Actions pane
In my case, there were rules for IIS URL Rewrite module but I didn't have that module installed. You should check your web.config if there are any modules included but not installed.
Your web.config describes that you're using forms authentication - make sure you enable forms authentication and disable anonymous authentication in IIS under the Authentication menu, for the website that is running in IIS.
I got Error Code 0x80070021 when migration IIS7 to IIS 10 in win 2016 box . .
Below steps helped me to fix it .
source
manually change value from "Deny" to "Allow" for below settings in
%windir%\system32\inetsrv\config\ applicationHost.config
under section:system.webServer
<section name="handlers" overrideModeDefault="Deny" />
Please <staticContent /> line and erased it from the web.config.
Well, we're using Amazon Web Services and so we are looking to use scripts and programs to get through this problem. So I have been on the hunt for a command line tool. So first I tried the trick of running
c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
but because I'm running a cloud based Windows Server 2012 it complained
This option is not supported on this version of the operating system. Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog, the Server Manager management tool, or the dism.exe command line tool. For more details please see http://go.microsoft.com/fwlink/?LinkID=216771.
and I Googled and found the official Microsoft Support Page KB2736284. So there is a command line tool dism.exe. So I tried the following
dism /online /enable-feature /featurename:IIS-ASPNET45
but it complained and gave a list of featurenames to try, so I tried them one by one and I tested my WebAPI webpage after each and it worked after the bottom one in the list.
dism /online /enable-feature /featurename:IIS-ApplicationDevelopment
dism /online /enable-feature /featurename:IIS-ISAPIFilter
dism /online /enable-feature /featurename:IIS-ISAPIExtensions
dism /online /enable-feature /featurename:IIS-NetFxExtensibility45
And so now I can browse to my WebAPI site and see the API information. That should help a few people. [However, I am not out of the woods totally myself yet and I cannot reach the website from outside the box. Still working on it.]
Also, I did some earlier steps following other people responses. I can confirm that the following Feature Delegation needs to be change (though I'd like to find a command line tool for these).
In Feature delegation
Change
'Handler Mappings' from Read Only to Read/Write
Change
'Modules' from Read Only to Read/Write
Change
'SSL Settings' from Read Only to Read/Write
Check if IIS server installed the URL rewrite feature.
If it is not installed then make sure your web.config file don't have the URL rewrite related configuration
<!-- Make sure don't have below config, if server have not installed url rewrite feature. -->
<rewrite>
<rules>
<rule name="Fail bad requests">
<match url=".*"/> ...
Some time we copied the config from legacy server and straight away deploy to brand new server, then we may encounter such kind of 500 issue.
Had this today on a Windows 2016 Core server I resolved the issue by ensuring the components were installed as mentioned by GIOESCOM and then I repaired the SDK's in my case for .NET Core 3.1, .NET 5 and .NET 6 which resolved the issue and the ASP.NET 4.7.2 MVC web app worked.
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”)
Hello guys
From older IIS and server
We may encounter the following error when we want to run our application on IIS 10 built on the new Microsoft Windows Server 2016.
HTTP Error 500.19 – Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false
The solution is very simple.
Follow the C:\Windows\System32\inetsrv\config file path from your computer. Change the overrideModeDefault=”Deny” part in the applicationHost config file to “Allow”. Then when you restart IIS, the problem will be fixed.
It works and save my time. Try it HTTP Error 500.19 – Internal Server Error – 0x80070021 (IIS 8.5)
The solution that worked for me was to delete my current Web.config and add a new one. That solved the problem for me

Using port 80 with IIS Express inside of VS2010

I've got an app that I am trying to run on my dev system under IIS Express from VS2010 that I need to use port 80 for, but I can't get it to work. I've looking up information talking about port 80 being reserved.
http://learn.iis.net/page.aspx/1005/handling-url-binding-failures-in-iis-express/
But even after doing that I still get an error from vs2010 that says
"Unable to launch the IIS Express Web server. Port '80' is in use."
I don't know what else to try. I've used Process Hacker to track down port 80 and it seems to be used by System running on process ID 4, which is the NT Kernel and System process. I don't know if that would prevent me from using the port though. I thought maybe that was a result of http.sys holding that port so nothing else could use it?
I did managed to get IIS Express to run on port 80 by modifying the default binding of the C:\Users\[MyUser]\Documents\IISExpress\config\applicationhost.config file, and while I can start IIS Express manually this way, VS then gets an error because a binding already exists on that port. So I change it back to 8080, create the virtual directory using the button within VS2010 (which I'm guessing is the same as entering a site binding) but I still get an error when I go to debug the application. Is there something hardcoded in VS2010 that won't let it start IIS Express on port 80?
UPDATE & FIX: Ok, so I found a few more things to check and I did resolve my problem but not completely. One post suggested making sure I did not have SQL reporting services installed as it can monitor on port 80, I used to have it installed but not anymore and was not the problem I was encountering. I did however realize that I have WebDeploy installed. It was bundled with the VS2010 SP1 bundle from the Web Platform Installer. This is fine as I do want the client tools from WebDeploy, but it also installed the agent on my system which was monitoring on port 80. I went to my list of services and stopped the Web Deploy Agent Service. Soon as I did this I can now use port 80 for IIS Express from within VS2010.
New Issue related to running on port 80 in IIS Express
However my application is an MVC3 App, and I've run into a problem because the MVC3 isn't capturing my request at all, so It's not firing my controller actions or anything like that, but a txt file in the root of my app can be reached so I know it's my site that IIS Express is serving up. Anyone have any issues running an MVC3 (I don't know if it's exclusive to MVC3 or not) in IIS Express on port 80?
Just posting my own answer for this problem so I can mark the question as answered.
Check http://learn.iis.net/page.aspx/1005/handling-url-binding-failures-in-iis-express/
Disable the Web Deploy Agent service if you have it installed.
in my case i solved the issue by stop "SQL Server Reporting Services"
you can find it in
control panel -> sevices
THANK YOU very much for you discovering of the 'Web Deploy Agent' service! This is something that only recently got turned on as I had all this working perfectly and just today installed the updated version of IIS Express, and ran into the exact same problem with port 80. So now that I have turned off the Web Deploy agent, my system works correctly again.
As for ASP.NET MVC3, that works great for me on port 80 and port 443. It was quite a bit of work to bind both those ports so that IIS Express was able to use them as a normal user (most of it from the link you posted above), and to install the SSL certificate we use. I manually created all the entries in my applicationhost.config file to get this working, and the appropriate sites section is below:
<sites>
<site name="PHP: A Main" id="2144116512">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\var\www\amain\www" />
<virtualDirectory path="/images" physicalPath="C:\var\www\images" />
</application>
<application path="/admin">
<virtualDirectory path="/" physicalPath="C:\var\www\amain\www\admin" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:test.amainhobbies.com" />
<binding protocol="https" bindingInformation="*:443:test.amainhobbies.com" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
Note that my site is a combined PHP and ASP.NET MVC3 site, as we are in the process of re-writing the entire thing to run on ASP.NET MVC3, so most of the site is still PHP but lots of new stuff is now running ASP.NET MVC3, and that stuff works for me.
Does your IIS Express work properly with MVC3 outside of Visual Studio, or is the MVC3 stuff just not working at all?
I didn't have the Web Deploy Agent installed but ran into this issue. You can also fix this by running this command to find out which application or service is using the port and then trace it down in Task manager.
netstat -o -n -a | findstr 0.0:80
Then open Task manager, go to Processes, click the checkbox "Show processes for all users" and then click the View menu and Go to the Columns, add the PID column.
Match the Process ID from the netstat command to the PID in task manager and you will find the service or application that's using the port.
That solution helped me.
On Windows 7 or Windows Vista, from an elevated command prompt, run the following command:
console
netsh http add urlacl url=http://localhost:80/ user=everyone
This command will allow any user's application (including your own IIS Express instances) to run using port 80 without requiring administrative privileges. To limit this access to yourself, replace "everyone" with your Windows identity.
Taken from that source -> https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/handling-url-binding-failures-in-iis-express

Resources