0

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 (i.e. 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.

Terry
  • 2,148
  • 2
  • 32
  • 53
  • What's the body of the 500 error say? – Shane Ray Feb 09 '17 at 23:20
  • Hmm, I'm in Chrome and don't see anything else. All I get is `The 192.168.100.14 page isn’t working. 192.168.100.14 is currently unable to handle this request. HTTP ERROR 500` And there is a 'Reload' button but nothing else. I didn't see anything in Chrome settings to turn on more details, but maybe I missed it. – Terry Feb 09 '17 at 23:25
  • Press f12 , reload the page, and check out the network inspector for more clues... – Shane Ray Feb 09 '17 at 23:28
  • Will do, Fiddler response gave me: `HTTP/1.1 500 Internal Server Error Content-Length: 0 Server: Microsoft-HTTPAPI/2.0 Date: Thu, 09 Feb 2017 23:27:37 GMT` Looks like Chrome Network tab gives same information. – Terry Feb 09 '17 at 23:31
  • Bummer, looks like there is no body. Next thing I would try is logging any unhandled exceptions and see if the exception message or stack trace is able to provide you with more info. – Shane Ray Feb 09 '17 at 23:33
  • Here's where my Owin inexperience is going to hurt me. I don't have that traditional 'middleware' pipeline thing going that I've seen in normal MVC apps. How do I go about getting an exception handler wired in? Right now, I have a `public void Configuration( IAppBuilder app )` method that does nothing more than `app.UseHangfireDashboard();` call. (Of course the `WebApp.Start( options );` method is called when the service starts). Any suggestions? – Terry Feb 09 '17 at 23:38
  • Sorry, I am mobile right now.. but check this http://stackoverflow.com/questions/30918649/unhandled-exception-global-handler-for-owin-katana – Shane Ray Feb 10 '17 at 00:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135391/discussion-between-terry-and-shane-ray). – Terry Feb 10 '17 at 14:47

1 Answers1

0

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.

Shane Ray
  • 1,449
  • 1
  • 13
  • 18