C# 如何解决服务器上的Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken CancellationToken)问题?

C# 如何解决服务器上的Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken CancellationToken)问题?,c#,C#,在本地,我的代码使用visual studio工作得非常完美,我正试图在heroku的docker的帮助下部署我的应用程序,因此我遇到了以下问题: heroku logs --tail --app=apipqr 2020-09-01T15:55:18.650830+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.&l

在本地,我的代码使用visual studio工作得非常完美,我正试图在heroku的
docker
的帮助下部署我的应用程序,因此我遇到了以下问题:

    heroku logs --tail --app=apipqr

    2020-09-01T15:55:18.650830+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()

    2020-09-01T15:55:18.650830+00:00 app[web.1]: --- End of stack trace from previous location where exception was thrown ---

    2020-09-01T15:55:18.650831+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    2020-09-01T15:55:18.650832+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.650832+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.650833+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.650834+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)

    2020-09-01T15:55:18.650834+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

    2020-09-01T15:55:18.668941+00:00 app[web.1]: Unhandled exception. System.Net.Sockets.SocketException (13): Permission denied

    2020-09-01T15:55:18.668943+00:00 app[web.1]: at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

    2020-09-01T15:55:18.668944+00:00 app[web.1]: at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

    2020-09-01T15:55:18.668945+00:00 app[web.1]: at System.Net.Sockets.Socket.Bind(EndPoint localEP)

    2020-09-01T15:55:18.668945+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()

    2020-09-01T15:55:18.668946+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)

    2020-09-01T15:55:18.668947+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()

    2020-09-01T15:55:18.668947+00:00 app[web.1]: --- End of stack trace from previous location where exception was thrown ---

    2020-09-01T15:55:18.668948+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    2020-09-01T15:55:18.668948+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.668949+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.668950+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

    2020-09-01T15:55:18.668951+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)

    2020-09-01T15:55:18.668951+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

    2020-09-01T15:55:18.668952+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

    2020-09-01T15:55:18.668952+00:00 app[web.1]: at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

    2020-09-01T15:55:18.668953+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

    2020-09-01T15:55:18.668953+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

    2020-09-01T15:55:18.668953+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

    2020-09-01T15:55:18.668954+00:00 app[web.1]: at apiPQR.Program.Main(String[] args) in /src/Program.cs:line 17

    2020-09-01T15:55:18.744599+00:00 heroku[web.1]: Process exited with status 134

    2020-09-01T15:55:18.789155+00:00 heroku[web.1]: State changed from starting to crashed

    2020-09-01T16:07:33.570625+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=cf995ff3-8ac8-4dbd-83d1-ccde110a85b4 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:07:35.077214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=7f3d6b2b-a22d-4668-bfba-0a7d761d03c0 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:03.406315+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/132364" host=apipqr.herokuapp.com request_id=0d8a3d19-bb9c-4db4-880b-789e70e5a3c8 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:03.797108+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=fc7ca617-8e1f-4968-8b1e-29696bace253 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:17.545896+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/pqrs/132364" host=apipqr.herokuapp.com request_id=f7a80646-2d8f-4756-88da-e1f6d00f2cad fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:18.538346+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=60ee6b50-f97b-452f-b53a-ba512f1148cf fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:25.328528+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/pqrs/132364" host=apipqr.herokuapp.com request_id=46cd0b26-5a9d-4753-acc8-9da9beadf301 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:08:25.704773+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=c9c36c3c-787b-4611-b7a5-21bc9701fcd5 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:14:17.698276+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/pqrs/132364" host=apipqr.herokuapp.com request_id=ba4c6733-4f20-4f33-a8dc-903315380516 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:14:18.235225+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=04947cff-0f19-4c55-a5c7-f2c20e7ea3a2 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:18:19.000000+00:00 app[api]: Build started by user prjchec.dagudelo@umanizales.edu.co

    2020-09-01T16:18:23.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/fb4266e8-692f-4803-aa4e-8abd4f5a9aac/activity/builds/75d75c9b-c0df-442d-b776-7153f78fd3ca

    2020-09-01T16:21:21.333218+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=70e4d34f-c4d1-4342-a40f-6f1d6e822d21 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:21:21.797341+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=6f7c5586-6015-474d-9e97-8cbd9b89280f fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:21:26.210559+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=59db4a66-4322-492b-82fd-936e33504078 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:21:26.509460+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=da1093e3-fa66-4f24-b04f-5facdc5bfe9a fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:25:50.475795+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=029e2506-c2d1-4955-841b-f5ad708a6b0c fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:25:51.080742+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=b5162d58-8aa1-4ded-bf27-1d3961a58304 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:28:09.668852+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=9c7a0a55-f368-413c-b482-1a99013b484e fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:28:10.263287+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=d114f738-6071-4830-96eb-51ee26521ece fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:28:18.927089+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/132364" host=apipqr.herokuapp.com request_id=453c0280-0cb4-41c8-85a1-ba054bf490b3 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:28:19.287270+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=83b6467b-f719-44fe-ad6b-7ac39df6ba1b fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:31:11.973420+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=7f38aa9d-14a6-41c8-a815-23a095b56e7d fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T16:31:12.536957+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=c916fdc6-5a43-4fe0-815b-4adc612ecf70 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-01T21:23:27.977046+00:00 heroku[web.1]: State changed from crashed to starting

    2020-09-01T21:23:32.339238+00:00 heroku[web.1]: Starting process with command `dotnet apiPQR.dll`

    2020-09-01T21:23:35.657769+00:00 app[web.1]: warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]

    2020-09-01T21:23:35.657973+00:00 app[web.1]: Storing keys in a directory '/app/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.

    2020-09-01T21:23:35.740283+00:00 app[web.1]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]

    2020-09-01T21:23:35.740285+00:00 app[web.1]: No XML encryptor configured. Key {d3cf2d8b-47ac-4fb6-8189-cb330c59ee9d} may be persisted to storage in unencrypted form.

    2020-09-01T21:23:36.024197+00:00 app[web.1]: crit: Microsoft.AspNetCore.Server.Kestrel[0]

    2020-09-01T21:23:36.024218+00:00 app[web.1]: Unable to start Kestrel.

    2020-09-01T21:23:36.024219+00:00 app[web.1]: System.Net.Sockets.SocketException (13): Permission denied

    2020-09-01T21:23:36.024221+00:00 app[web.1]: at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

    2020-09-01T21:23:36.024221+00:00 app[web.1]: at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

    2020-09-01T21:23:36.024222+00:00 app[web.1]: at System.Net.Sockets.Socket.Bind(EndPoint localEP)

    2020-09-01T21:23:36.024222+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()

    2020-09-01T21:23:36.024227+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)

    2020-09-01T21:23:36.024228+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()

    2020-09-01T21:23:36.024228+00:00 app[web.1]: --- End of stack trace from previous location where exception was thrown ---

    2020-09-01T21:23:36.024229+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    2020-09-01T21:23:36.024230+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.024230+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.024230+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.024231+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)

    2020-09-01T21:23:36.024231+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

    2020-09-01T21:23:36.050996+00:00 app[web.1]: Unhandled exception. System.Net.Sockets.SocketException (13): Permission denied

    2020-09-01T21:23:36.050999+00:00 app[web.1]: at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

    2020-09-01T21:23:36.050999+00:00 app[web.1]: at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

    2020-09-01T21:23:36.051000+00:00 app[web.1]: at System.Net.Sockets.Socket.Bind(EndPoint localEP)

    2020-09-01T21:23:36.051001+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()

    2020-09-01T21:23:36.051002+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)

    2020-09-01T21:23:36.051002+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass21_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()

    2020-09-01T21:23:36.051003+00:00 app[web.1]: --- End of stack trace from previous location where exception was thrown ---

    2020-09-01T21:23:36.051003+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)

    2020-09-01T21:23:36.051004+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.051005+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.051005+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

    2020-09-01T21:23:36.051006+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)

    2020-09-01T21:23:36.051007+00:00 app[web.1]: at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

    2020-09-01T21:23:36.051007+00:00 app[web.1]: at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

    2020-09-01T21:23:36.051008+00:00 app[web.1]: at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

    2020-09-01T21:23:36.051008+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

    2020-09-01T21:23:36.051009+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

    2020-09-01T21:23:36.051009+00:00 app[web.1]: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

    2020-09-01T21:23:36.051371+00:00 app[web.1]: at apiPQR.Program.Main(String[] args) in /src/Program.cs:line 17

    2020-09-01T21:23:36.153081+00:00 heroku[web.1]: Process exited with status 134

    2020-09-01T21:23:36.197815+00:00 heroku[web.1]: State changed from starting to crashed

    2020-09-02T01:45:58.153158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=faace7be-de26-4790-a9d0-162ea66cd8de fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-02T01:45:59.000006+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=e1666af7-3af7-4d35-a2b1-4a168a70aaf0 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-02T01:47:18.324747+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=apipqr.herokuapp.com request_id=808f31a8-6b32-4a09-95d1-5588cf4446cd fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https

    2020-09-02T01:47:18.718403+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=apipqr.herokuapp.com request_id=7e2434aa-1621-4016-b70b-89161a06b452 fwd="190.70.235.79" dyno= connect= service= status=503 bytes= protocol=https
startup.cs

    using apiPQR.Contexts;

    using Microsoft.AspNetCore.Builder;

    using Microsoft.AspNetCore.Hosting;

    using Microsoft.Extensions.Configuration;

    using Microsoft.Extensions.DependencyInjection;

    using Microsoft.Extensions.Hosting;

    using Microsoft.EntityFrameworkCore;

    using Microsoft.AspNetCore.Authentication.JwtBearer;

    using Microsoft.IdentityModel.Tokens;

    using System.Text;

    using System;

    namespace apiPQR

    {

        public class Startup

        {

            public Startup(IConfiguration configuration)

            {

                Configuration = configuration;

            }

            public IConfiguration Configuration { get; }

            // This method gets called by the runtime. Use this method to add services to the container.

            public void ConfigureServices(IServiceCollection services)

            {

                services.AddControllers();

                services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ConnectionString")));

                services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>

                {

                    options.TokenValidationParameters = new TokenValidationParameters

                    {

                        ValidateIssuer = false,

                        ValidateAudience = false,

                        ValidateLifetime = true,

                        ValidateIssuerSigningKey = true,

                        IssuerSigningKey = new SymmetricSecurityKey(

                        Encoding.UTF8.GetBytes(Configuration["jwt:key"])),

                        ClockSkew = TimeSpan.Zero

                    };

                }

                );

            }

            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

            {

                if (env.IsDevelopment())

                {

                    app.UseDeveloperExceptionPage();

                }

                app.UseHttpsRedirection();

                app.UseRouting();

                app.UseAuthorization();

                app.UseEndpoints(endpoints =>

                {

                    endpoints.MapControllers();

                });

            }

        }

    }
使用apiPQR.context;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Hosting;
使用Microsoft.EntityFrameworkCore;
使用Microsoft.AspNetCore.Authentication.JwtBearer;
使用Microsoft.IdentityModel.Tokens;
使用系统文本;
使用制度;
名称空间apiPQR
{
公营创业
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddControllers();
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“ConnectionString”));
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(选项=>
{
options.TokenValidationParameters=新的TokenValidationParameters
{
validateisuer=false,
ValidateAudience=false,
ValidateLifetime=true,
ValidateSuersigningKey=true,
IssuerSigningKey=新对称安全密钥(
Encoding.UTF8.GetBytes(配置[“jwt:key”]),
时钟偏移=时间跨度0
};
}
);
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
});
}
}
}

有人知道怎么解决吗?谢谢。

你能把你的
Startup.cs
文件也发出去吗?启动应用程序时的异常也可能是该文件中发生的配置内容。它可能会向我们指出问题的方向。看起来您已经切断了异常跟踪的顶部,该跟踪将包含更多详细信息,如消息。@JeremyLakeman I更新我的代码,感谢您为我所做的一切“未处理的异常。System.Net.Sockets.SocketException(13):权限被拒绝”。。。“位于System.Net.Sockets.Socket.Bind(端点localEP)”。操作系统不允许你监听网络套接字。@JeremyLakeman请原谅我的无知,我能做些什么来解决这个问题?
    using apiPQR.Contexts;

    using Microsoft.AspNetCore.Builder;

    using Microsoft.AspNetCore.Hosting;

    using Microsoft.Extensions.Configuration;

    using Microsoft.Extensions.DependencyInjection;

    using Microsoft.Extensions.Hosting;

    using Microsoft.EntityFrameworkCore;

    using Microsoft.AspNetCore.Authentication.JwtBearer;

    using Microsoft.IdentityModel.Tokens;

    using System.Text;

    using System;

    namespace apiPQR

    {

        public class Startup

        {

            public Startup(IConfiguration configuration)

            {

                Configuration = configuration;

            }

            public IConfiguration Configuration { get; }

            // This method gets called by the runtime. Use this method to add services to the container.

            public void ConfigureServices(IServiceCollection services)

            {

                services.AddControllers();

                services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ConnectionString")));

                services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>

                {

                    options.TokenValidationParameters = new TokenValidationParameters

                    {

                        ValidateIssuer = false,

                        ValidateAudience = false,

                        ValidateLifetime = true,

                        ValidateIssuerSigningKey = true,

                        IssuerSigningKey = new SymmetricSecurityKey(

                        Encoding.UTF8.GetBytes(Configuration["jwt:key"])),

                        ClockSkew = TimeSpan.Zero

                    };

                }

                );

            }

            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

            {

                if (env.IsDevelopment())

                {

                    app.UseDeveloperExceptionPage();

                }

                app.UseHttpsRedirection();

                app.UseRouting();

                app.UseAuthorization();

                app.UseEndpoints(endpoints =>

                {

                    endpoints.MapControllers();

                });

            }

        }

    }