HttpListener in UWP application leads to "An attempt was made to access a socket in a way forbidden by its access permission"s #2768
llfab
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have created an UWP application and wanted to run our REST server that contains a HttpListener. While starting HttpListener the following exception happened: "An attempt was made to access a socket in a way forbidden by its access permissions"
I had the REST server already running in WPF-based .net6.0 applications. For these to be able to listen on the specified URL, you need to add the URI to the URL access control list via
netsh http add urlacl ...
. Other than that I had not seen any problems.I also found this helpful information that UWP apps cannot receive networking from the loopback. You will find how to make that work here: https://social.msdn.microsoft.com/Forums/en-US/d7e12fe4-cddd-4365-abda-5d5ada33410d/are-any-special-step-required-for-uwp-httplistener?forum=wpdevelop
While looking through the web for others having the same issue, I was not able to find anything relevant to my specific problem. Trying with different URIs using both http and https I was finally able to detect the root cause:
In URLACL the URI is regeistered and access-allowed for a user. In my case "Everyone". Even if I do not fully understand why this would enable .net6.0 apps to successfully start a HttpListener on these URI's while it would fail UWP apps for the same, I now recognize that I will need different base URIs for my .net6.0 and UWP apps.
Maybe you guys can attach more details to this discussion allowing others to not fall into the same trap
Beta Was this translation helpful? Give feedback.
All reactions