问题
I have a self-hosted OWIN project that I'm trying to run. It is configured to listen on:
http://localhost:8080
Whenever I try to access that URL I get an HTTP Error 503. The service is unavailable error.
I have run netstat -a -b
and made absolutely sure there's no other application running on port 8080.
When I change the configuration to http://+:8080
the project works fine. So the only change is localhost
to +
.
Now here's the weird things:
I made sure all entries (
localhost:8080
or+:8080
) in the HTTP namespace are identical (See this and this, where "iedereen" is dutch for "everyone" (and, yes, this is only on my test-station)). Relevant output ofnetsh http show urlacl
:URL Reservations: Reserved URL : http://+:8080/ User: \Everyone Listen: Yes Delegate: Yes SDDL: D:(A;;GAGXGWGR;;;WD) Reserved URL : http://localhost:8080/ User: \Everyone Listen: Yes Delegate: Yes SDDL: D:(A;;GAGXGWGR;;;WD)
I have the same issue on port 8081 or other ports; "
+
" works, "localhost
" doesn't. So to make sure there wasn't something conflicting with 8080 I've tried 8081 (and other ports, and, ofcourse, with the correct urlacl's)- When I use
+:8080
the application can be reached fine; I get the desired response. So it's not a firewall issue. Nor is it for port 8081 or other ports I've tried. Also, the503
comes from the application (it is an application error after all, but also: when I stop the application I simply get no response instead of a 503), so, again, no firewall issue. - I tried running as administrator to no avail, same for running VS as administrator.
localhost:8080
works on a coworker's computer (which is how this came up in the first place)localhost
resolves fine to127.0.0.1
and::1
. No altered hosts file.
I can't seem to debug this issue, I can set a breakpoint in my controller method but it is never reached. The application starts fine.
Ok, to the test-code to reproduce:
using Microsoft.Owin.Hosting;
using Owin;
using System;
namespace TestApp
{
internal class Program
{
private static void Main(string[] args)
{
using (WebApp.Start<WebAppStartup>("http://localhost:8080"))
{
Console.WriteLine("Press [enter] to quit...");
Console.ReadLine();
}
}
}
internal class WebAppStartup
{
public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("Hello, world.");
});
}
}
}
Again, the above doesn't work unless I change localhost
to +
.
My main question is: is there a way I can debug this? I get no exceptions on starting the application but the controller method is never reached (or: in the above code, the "Hello, world" is never returned). I've checked the windows eventlog but nothing there.
Note: My problem is not actually a problem (since I have a 'workaround'); when I simply change the config to use http://+:8080
but at this point it's a matter of principle and I'd like to know why +
works and localhost
doesn't.
I am mostly interested in how to debug this and what the difference between localhost
and +
is; how to configure OWIN or where to set a breakpoint to see the request come in or the 503 response being sent out or how to get this logged or...
Edit: I have changed the code to read:
using Microsoft.Owin;
using Microsoft.Owin.Hosting;
using Owin;
using System;
using System.Threading.Tasks;
namespace TestApp
{
internal class Program
{
private static void Main(string[] args)
{
using (WebApp.Start<WebAppStartup>("http://localhost:8080/")) // or: http://+:8080/
{
Console.WriteLine("Press [enter] to quit...");
Console.ReadLine();
}
}
}
internal class WebAppStartup
{
public void Configuration(IAppBuilder app)
{
app.Use<TestMiddleware>();
app.Run(context =>
{
context.Response.ContentType = "text/plain";
Console.WriteLine("Sending response");
return context.Response.WriteAsync("Hello, world.");
});
}
}
public class TestMiddleware : OwinMiddleware
{
public TestMiddleware(OwinMiddleware next) : base(next) { }
public override async Task Invoke(IOwinContext context)
{
Console.WriteLine("Begin Request");
await Next.Invoke(context);
Console.WriteLine("End Request");
}
}
}
When I run the application with http://+:8080
I see the following appear in my console:
Begin Request
Sending response
End Request
And also "Hello, world" appears in my browser. I can set a breakpoint on the "begin request" line and it gets hit. Then, again, I change to http://localhost:8080
and ... HTTP Error 503. The service is unavailable.
. Again. Console shows nothing (besides the obvious "Press [enter] to quit..."), the breakpoint is not hit.
来源:https://stackoverflow.com/questions/53667946/self-hosted-owin-project-http-localhost8080-wont-work-http-8080-does