简体   繁体   中英

Urls exposed by Microsoft.Owin.Hosting.WebApp.Start from within Windows Service are not accessible on remote machines

I've created a Windows Service (using Topshelf package) that uses WebApp.Start to listen to http requests. My code is as follows:

    var options = new StartOptions();
    options.Urls.Add( "http://localhost:9095" );
    options.Urls.Add( "http://127.0.0.1:9095" );
    options.Urls.Add( $"http://{ConfigurationHelper.IPAddress}:9095" );
    options.Urls.Add( $"http://{Environment.MachineName}:9095" );

    Microsoft.Owin.Hosting.WebApp.Start<Startup>( options );

I can hit all the desired URLs when I'm browsing on the Windows Service machine, but when I'm on a remote machine on the same network with access to the machine, I get a 500 error when hitting the URL (ie http://192.168.100.14:9095/hangfire/ ).

Some notes:

  1. Windows Firewall is turned off, but I'm still confirming with IT whether or not our hardware firewall might be blocking something (would we get 500 if that was case or 404?)

  2. The windows service is running as a local user that is part of the Administrators group.

  3. For each of those URLs, I ran the netsh command: netsh http add urlacl url=http://127.0.0.1:9095/ user=myAdminUser

Any other ideas on why I'd get a 500 or how to see any diagnostic information anywhere? (debug view and event viewer have nothing).

It is my first Owin application, so I'm very green on it yet.

Update: OWIN error trace

[8496] BTR.Evolution.Service OWIN Exception: Object reference not set to an instance of an object.
[8496]
[8496] at Hangfire.Dashboard.MiddlewareExtensions.Unauthorized(IOwinContext owinContext)
[8496] at Hangfire.Dashboard.MiddlewareExtensions.<>c__DisplayClass1_2.b__1(IDictionary`2 env)
[8496] at Microsoft.Owin.Mapping.MapMiddleware.d__0.MoveNext()
[8496] --- End of stack trace from previous location where exception was thrown ---
[8496] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[8496] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[8496] at BTR.Evolution.Service.GlobalExceptionMiddleware.d__1.MoveNext() in C:\\BTR\\Source\\Evolution.Service\\BTR.Evolution.Service\\Startup.cs:line 20

So maybe it wasn't OWIN that was the culprit but rather Hangfire and my attempt to use it remotely. Going to look into authorization filter to see if that will help.

Look into how to get the stack trace from the exception by creating an OWIN middleware logger. See Unhandled Exception Global Handler for OWIN / Katana? for more details.

Judging by the update that includes the stack trace you need to look into auth issues within hangfire. Check out http://docs.hangfire.io/en/latest/configuration/using-dashboard.html#configuring-authorization - This states that for security reasons, by default only local request are allowed. It also provides sample code showing how to use IAuthorizationFilter to allow remote request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM