1

以下は、エンドポイントが既に使用されているという例外をスローします。

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World 1");
        });
    }
}

public class Startup1
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World!");
        });
    }
}
public class Program
{
    public static void Main(string[] args)
    {

        string serverUrl = $"http://localhost:4000/test1/";

        var _webHost = new WebHostBuilder().UseKestrel()
                                        .UseContentRoot(Directory.GetCurrentDirectory())
                                        .UseStartup<Startup>()
                                        .UseUrls(serverUrl)
                                         .UseIISIntegration()
                                        .Build();

        _webHost.Start();

        string serverUrl1 = $"http://localhost:4000/test2/";
        var _webHost1 = new WebHostBuilder().UseKestrel()
                                       .UseContentRoot(Directory.GetCurrentDirectory())
                                       .UseStartup<Startup1>()
                                       .UseIISIntegration()
                                       .UseUrls(serverUrl1)
                                       .Build();

        _webHost1.Start();

        Console.ReadLine();
    }
}

未処理の例外: System.AggregateException: 1 つ以上のエラーが発生しました。(エラー -4091 EADDRINUSE アドレスは既に使用されています) ---> Microsoft.AspNetCore.Server.Kestrel.Networking.UvException: エラー -4091 EADDRINUSE アドレスは既に Microsoft.AspNetCore.Server.Kestrel.Networking.Libuv.Check(Int32 で使用されています) statusCode) で Microsoft.AspNetCore.Server.Kestrel.Networking.UvStreamHandle.Listen(Int32 バックログ、アクション4 callback, Object state) at Microsoft.AspNetCore.Server.Kestrel.Http.TcpListenerPrimary.CreateListenSocket() at Microsoft.AspNetCore.Server.Kestrel.Http.Listener.<>c.<StartAsync>b__6_0(Object state) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Http.ListenerPrimary.<StartAsync>d__9.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.KestrelEngine.CreateServer(ServerAddress address) at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication1 アプリケーション) で Microsoft.AspNetCore.Hosting.Internal.WebHost.Start() で ConsoleApp1.Program.Main(String[] args)何かキーを押すと続行します 。. .

owin と httplistener のように、異なる仮想パスを使用して同じポートに 2 つのリスナーを配置する方法はありますか?

4

2 に答える 2

2

いいえ、Kestrel はこれをサポートしていません。ただし、WebListener と IIS はそうします。

于 2016-06-16T21:12:39.067 に答える