12

When specifying a port to bind to with .UseKestrel() I get the errors listed below.. but if I remove the kestrel options everything works normally if I check the API from my browser.

I've tried binding to the port that my application defaults to with no ports chosen and I've tried checking netstat to actively avoid any ports that are in use. Nothing works but removing the options entirely. This is not replicated on my Mac or another Windows 10 machine. This device is Windows 10.

.UseKestrel(options =>
{
    options.Listen(IPAddress.Loopback, 50470);
    options.Listen(IPAddress.Any, 80);
})

: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'http://localhost:50470/'. Binding to endpoints defined 
in UseKestrel() instead.
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.Net.Sockets.SocketException (10013): An attempt was made to access a 
socket in a way forbidden by its access permissions
at 
System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException
(SocketError error, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress 
socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.
BindAsync() at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer. 
<>c__DisplayClass21_01.<<StartAsync>g__OnBind|0>d.MoveNext() ` 
2
  • Is it the same user on both Windows machines? "...forbidden by its access permissions" could point to a group policy setting.
    – Duston
    Feb 13, 2019 at 14:50
  • It is not, they are different computers entirely and another person running the code.
    – Ping Pong
    Feb 13, 2019 at 15:23

7 Answers 7

27

Also check Darkthread's answer here: https://superuser.com/questions/1486417/unable-to-start-kestrel-getting-an-attempt-was-made-to-access-a-socket-in-a-way

We discovered that a port we had been using for a long time wasn't acccessible anymore because it had been reserved by Windows! You may wish to check reserved ports using this command: netsh interface ipv4 show excludedportrange protocol=tcp

3
  • 1
    Had this same problem and this was the only thing that helped me hunt it down. Why is Windows now setting such large ranges of port reservations?
    – slasky
    Mar 17, 2020 at 18:27
  • 1
    Yes this was the only thing that helped. Microsoft should document this.
    – pantonis
    Mar 27, 2020 at 9:17
  • superuser.com/questions/1579346/…
    – RouR
    Jul 16, 2022 at 8:04
6

After Windows Update, some ports are reserved by Windows and applications cannot bind to these ports. please check this command for forbiden port on Os

netsh interface ipv4 show excludedportrange protocol=tcp

2

In my case, Removing invalid local IP and Port address combinations from the app's launchSettings.json did it.

1

The additional binding of port 80 in ".UseKestrel(options => { options.Listen(...) })" was causing the issue in my case.

1

When you run an ASP.NET Core application directly through Kestrel, without an additional reverse proxy like IIS or nginx, you will need to configure the hosting URL properly.

The problem was because, you did not follow Port sharing limitation in Kestrel web server.

When you to use the Kestrel web server, you should set unique port to app. (if you use the port 80, make sure no apps use this port). and your app has enough permissions, too.

more info:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2

I hope is useful.

0

Try Updating The Https Certificate with this command. It worked for me!!

dotnet dev-certs https
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 8, 2022 at 20:36
-1

The problem was with the additional binding of port 80, updating this corrected the problem.

1
  • 1
    are you able to explain what did you do to fix this a little better? Where did you update the binding? on the IIS?
    – tonycdp
    May 17, 2019 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.