Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When self-hosting what exactly causes AddressAccessDeniedException : HTTP could not register URL

I am writing a bdd test for a component that will startup phantomjs and hit a specific route on my site and do processing on that. Because the component is fundamentally about automating a phantom instance there is no way to easily stub out the http requests.

So I want to stub out a self-hosted endpoint that will stub out the data I'm after. Because this is a unit test I think its really important for it to run in isolation so I do something like this:

   async Task can_render_html_for_slide_async() {
        var config = new HttpSelfHostConfiguration("http://localhost:54331");
        config.Routes.MapHttpRoute("Controller", "{controller}", new {});
        using (var server = new HttpSelfHostServer(config)) {
            server.OpenAsync().Wait();
            var client = new HttpClient();
            var resp = await client.GetStringAsync(config.BaseAddress+"/Stub");
            Console.WriteLine(resp);
        }
    }

public class StubController : ApiController
{
    public string Get() {
        return "Booyah";
    }
}

Which gets me

AddressAccessDeniedException : HTTP could not register URL http://+:54331/

I understand that netsh or Admin mode is required for this but I don't understand why. Nodejs for example runs perfectly fine on windows but has no such requirement.

Also using OWIN directly needs no netsh-ing. So....what's going on?

like image 297
George Mauer Avatar asked Mar 26 '14 19:03

George Mauer


1 Answers

I wrote an article about it on codeproject, it was done to make it possible for multiple application to share the same port. You can have both, IIS and Apache (or OWIN in your case) listenening port 80. The routing to the right application is done thanks to the path of the url. IIS and Apache both would use this driver (http.sys). But you need permission to "reserve" a path. Administrators are always authorized. For other users, use netsh or my GUI tool HttpSysManager to set ACL.

like image 154
Nicolas Dorier Avatar answered Sep 25 '22 16:09

Nicolas Dorier