Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法启动红隼。无法绑定到已在使用的地址_C#_Asp.net_.net_Asp.net Core_Process - Fatal编程技术网

C# 无法启动红隼。无法绑定到已在使用的地址

C# 无法启动红隼。无法绑定到已在使用的地址,c#,asp.net,.net,asp.net-core,process,C#,Asp.net,.net,Asp.net Core,Process,我想从我创建的API启动一个.NETCore应用程序,该API也在.NETCore中 我在Program.cs文件中添加了UseUrls()函数,因此它将使用我希望它使用的端口。这是另一个模块的Program.cs public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost Bu

我想从我创建的API启动一个.NETCore应用程序,该API也在.NETCore中

我在Program.cs文件中添加了
UseUrls()
函数,因此它将使用我希望它使用的端口。这是另一个模块的Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://*:50003")
            .UseKestrel(options =>
            {
                options.Limits.MaxRequestBodySize = null;
            }
            )
            .UseDefaultServiceProvider(options =>
                options.ValidateScopes = false)
            .Build();
}
但是当我运行它时,
output
变量返回一个错误,它说

Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:4221: 
address already in use
我不知道为什么它试图用
4221
端口启动应用程序,而它是在Program.cs中编写的,以使用端口
50003

因此,如果我在CMD中手动编写,相同的命令
dotnet run
可以正常工作,如果我在代码中键入,它就不会正常工作

“使用C:\Users\StarTech\Desktop\Actibook Actibook\Actibook backend\ServerCore\TimeFrame.Actibook.WebService\wwwroot\Packages\2018-6-Friday031203SampleConverter\Properties\launchSettings.json…\r\n启动设置:Microsoft.AspNetCore.Server.Kestrel[0]\r\n无法启动Kestrel。\r\n System.IO.IOException:无法绑定到地址:地址已在使用。-->Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.AddressInUseException:错误-4091 EADDRINUSE地址已在使用---->Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException:错误r-4091 EADDRINUSE地址已在Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.ThrowError(Int32状态码)\r\n在Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.tcp_getsockname(uvtchandle handle,SockAddr&addr,Int32&namelen)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.ListenTcp(布尔useFileHandle)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.creatensocket()\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener.c.b_u8_0(侦听器侦听器)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.CallbackAdapter
1.c.b_u3_1(对象回调,对象状态)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.DoPostWork()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处\r\n在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification处(任务任务)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerPrimary.d_u15.MoveNext()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n位于System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n位于System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.d\u 20.MoveNext()\r\n---内部异常堆栈跟踪的结尾---\r\n位于Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.d\u 20.MoveNext()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处\r\n在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification处(任务任务)\r\n在Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.c_\u DisplayClass23\u 0
1.d.MoveNext()\r\n--从引发异常的上一个位置开始的堆栈结束跟踪---\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d\u 5.MoveNext()中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d\u 5.MoveNext()中\r\n---内部异常堆栈跟踪的结尾---\r\n\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)\r\n在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d\u 6.MoveNext()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)\r\n在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d\u 7.MoveNext()上\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处\r\n在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification处(任务任务)\r\n位于Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressStrategy.d\u 2.MoveNext()\r\n--从引发异常的前一个位置开始的堆栈结束跟踪---\r\n位于System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n位于Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.d\u 0.MoveNext()\r\n---来自引发异常的上一个位置的堆栈结束跟踪----\r\n位于System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n位于Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.d_23`1.MoveNext()\r\n

launchSettings.json contanis:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:60924/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "SampleConverter": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:60925/"
    }
  }
}

像这样的工作吗?这就是我的API在不久前的设置方式

  public static IWebHost BuildWebHost(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
            options=>
            {                    
                options.Listen(IPAddress.Any, 50003);
                options.Limits.MaxRequestBodySize = null;
            })
        )
        .UseDefaultServiceProvider(options =>
            options.ValidateScopes = false)
        .Build();
公共静态IWebHost BuildWebHost(字符串[]args)=>
韦伯霍
  public static IWebHost BuildWebHost(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
            options=>
            {                    
                options.Listen(IPAddress.Any, 50003);
                options.Limits.MaxRequestBodySize = null;
            })
        )
        .UseDefaultServiceProvider(options =>
            options.ValidateScopes = false)
        .Build();