自主OWIN项目; http:// localhost:8080不起作用,http:// +:8080呢?

Rob*_*III 5 .net c# owin

我有一个我正在尝试运行的自托管OWIN项目.它被配置为监听:

http://localhost:8080

每当我尝试访问该URL时,我都会收到HTTP错误503.服务不可用错误.

我已经运行netstat -a -b并且绝对确定在端口8080上没有运行其他应用程序.

当我将配置更改为http://+:8080项目工作正常.所以,唯一的变化是localhost+.

现在这里是奇怪的事情:

  • 我确信所有条目(localhost:8080+:8080在HTTP命名空间)是相同的(见,其中"iedereen"是荷兰语中是"大家"(是的,这只是我的测试站)).相关产出netsh 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) 
    
    Run Code Online (Sandbox Code Playgroud)
  • 我在端口8081或其他端口上遇到同样的问题; " +"有效," localhost"没有.因此,为了确保没有与8080冲突的东西我已经尝试过8081(以及其他端口,当然还有正确的urlacl)

  • 当我使用+:8080该应用程序时可以达到罚款; 我得到了理想的回应.所以这不是防火墙问题.也不是我尝试过的8081端口或其他端口.此外,503它来自应用程序(毕竟它是一个应用程序错误,但是:当我停止应用程序时,我只是没有响应而不是503),所以,再次,没有防火墙问题.
  • 我尝试以管理员身份运行无效,同样以管理员身份运行VS.
  • localhost:8080 适用于同事的计算机(这首先出现在这个位置)
  • localhost解决好127.0.0.1::1.没有改变的主机文件.

我似乎无法调试此问题,我可以在我的控制器方法中设置断点,但它永远不会到达.申请开始很好.

好的,要重现的测试代码:

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.");
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

同样,除非我改为localhost,否则上述内容不起作用+.

我的主要问题是:有没有办法可以调试这个?我没有启动应用程序的例外但是从未达到控制器方法(或者:在上面的代码中,永远不会返回"Hello,world").我已经检查了windows eventlog,但没有.

注意:我的问题实际上不是问题(因为我有'解决方法'); 当我只是改变配置使用http://+:8080 在这一点上这是一个原则的问题,我想知道为什么 +工作,而localhost不是.

我在如何调试这个最感兴趣和有什么区别localhost+是; 如何配置OWIN或在哪里设置断点以查看请求进来或503响应被发送或如何记录或...


编辑:我已将代码更改为:

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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时,http://+:8080我看到我的控制台中出现以下内容:

Begin Request
Sending response
End Request
Run Code Online (Sandbox Code Playgroud)

此外,我的浏览器中还出现"Hello,world".我可以在"开始请求"行设置一个断点,然后它就会被击中.然后,再说,我更改为http://localhost:8080和...... HTTP Error 503. The service is unavailable..再次.控制台什么都没显示(除了显而易见的"按[enter]退出..."),断点没有被击中.