Hosting icon indicating copy to clipboard operation
Hosting copied to clipboard

Hosting with Microsoft.AspNet.Server.WebListener does not work in RC1

Open BillDines opened this issue 11 years ago • 9 comments

Functional impact

If you use Microsoft.AspNet.Server.WebListener as your server when hosting an Asp.Net 5 application it fails during startup, terminating the process.

Minimal repro steps

  1. Run Visual Studio 2015 Update 1 NOT as an administrator*

  2. Create a new Asp.Net 5 project using the project template in Visual Studio 2015 Update 1

  3. Add a dependency to Microsoft.AspNet.Server.WebListener in project.json.

    "dependencies": { ...., "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final", .... },

  4. Add a new command for WebListener "commands": { ..., "webListener": "Microsoft.AspNet.Server.WebListener", ... },

  5. Start the webListener Command.

Expected result

A console app should start, hosting the web application using WebListener and listening on port 5000 (this worked OK in beta-8)

Actual result

The console app crashes with the following exception:

Microsoft.Net.Http.Server.WebListener: Information: Start Microsoft.Net.Http.Server.WebListener: Information: Listening on prefix: http://localhost:5000/ Microsoft.Net.Http.Server.WebListener: Error: Start Microsoft.Net.Http.Server.WebListenerException (0x80004005): Access is denied at Microsoft.Net.Http.Server.UrlPrefixCollection.RegisterPrefix(String uriPrefix, Int32 contextId) at Microsoft.Net.Http.Server.UrlPrefixCollection.RegisterAllPrefixes() at Microsoft.Net.Http.Server.WebListener.Start()

Further Information

Firewall is configured correctly to allow listening on port 5000. This can be tested by using Microsoft.AspNet.Server.Kestrel instead, which works fine. The host machine is running Windows 7 Professional Service Pack 1

*WebListener will start if run as an administrator but you get "HTTP Error 503. The service is unavailable" if you try and access the application.

BillDines avatar Nov 24 '15 15:11 BillDines

Are you trying to run this behind the platform handler? That's not supported. Use kestrel.

davidfowl avatar Nov 24 '15 19:11 davidfowl

@davidfowl - do you mean IISPlatformHandler? As in app.UseIISPlatformHandler() in Startup.Configure()? The behaviour is the same with or without it. I want to self host the application on Windows (i.e. no IIS) and I need Windows Authentication so I think WebListener is my only option??

BillDines avatar Nov 25 '15 10:11 BillDines

WebListener self-host should be fine, just don't use it with IIIS/Express (the default F5 in VS).

Tratcher avatar Nov 25 '15 16:11 Tratcher

That port may have been reserved for another app. See netsh.exe. You can try another port by adding "webListener": "Microsoft.AspNet.Server.WebListener --server.urls=http://localhost:5001/"

Tratcher avatar Nov 25 '15 16:11 Tratcher

@Tratcher Thanks for the response.

At some point I had used netsh to allow listnening on port 5000 for the user I am using to run the asp.net application:

netsh http add urlacl url=http://+:5000/ user=

Until now I thought that was required to allow listening for http on a port. In fact it prevents you listening on a port with WebListener! Kestrel will work though.

BillDines avatar Nov 26 '15 09:11 BillDines

As far as I am concerned the issue can be closed, but I am not sure I am able to do it??

BillDines avatar Nov 26 '15 09:11 BillDines

The issue is that the url you pass into netsh must match the one you give to weblistener. You do not need to preregister with netsh for localhost or running as admin.

Kestrel is unaffected by netsh because it uses raw sockets, not http.sys.

Tratcher avatar Nov 26 '15 14:11 Tratcher

I thought the url did match, but maybe I was missing a / or "+" doesn't work in this instance. Anyway, I am working with localhost, which is all I need right now. Now I know what is required I'm sure I can work out what I need to do when I want to access my application from remote machines.

Thanks for your help.

BillDines avatar Nov 26 '15 14:11 BillDines

  • does not match localhost from a registration perspective, registrations need to be exact string matches. If you used + in both places then it would match localhost sent from the client.

Tratcher avatar Nov 26 '15 14:11 Tratcher