Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Fehler: An unhandled exception occurred while processing the request. HttpRequestException: Failed to proxy the request to http://localhost:4200/,

08.07.2021 (👁39171)


Fehlermeldung

 in Asp Angular Anwendung

HttpRequestException: Failed to proxy the request to http://localhost:4200/, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://localhost:4200/.


Video


 

An unhandled exception occurred while processing the request.

Lösung:

In der Datei startup.cs in Asp.Net Core  muss man die Zeilen einfügen

spa.UseAngularCliServer(npmScript: "start");

spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");

 

                   

Code: Startup.cs

using Angular_ASP.Data;

using Angular_ASP.Models;

using Microsoft.AspNetCore.Authentication;

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.AspNetCore.HttpsPolicy;

using Microsoft.AspNetCore.Identity;

using Microsoft.AspNetCore.Identity.UI;

using Microsoft.AspNetCore.SpaServices.AngularCli;

using Microsoft.EntityFrameworkCore;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.DependencyInjection;

using Microsoft.Extensions.Hosting;

 

namespace Angular_ASP

{

    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)

        {

            //--------< ConfigureServices() >--------

            services.AddDbContext<ApplicationDbContext>(options =>

            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            //options.UseSqlServer("Server=.\\sqlexpress;Database=codedocu_de;Trusted_Connection=True;MultipleActiveResultSets=true"));

           

 

            services.AddDatabaseDeveloperPageExceptionFilter();

 

            services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)

                .AddEntityFrameworkStores<ApplicationDbContext>();

 

            services.AddIdentityServer()

                .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

 

            services.AddAuthentication()

                .AddIdentityServerJwt();

 

            services.AddControllersWithViews();

           

            services.AddRazorPages();

            // In production, the Angular files will be served from this directory

            //in Angular->/dist in React->/build

            services.AddSpaStaticFiles(configuration =>

            {

                configuration.RootPath = "ClientApp/dist";

            });

            //--------</ ConfigureServices() >--------

        }

 

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

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

            //--------< Configure() >-----

            if (env.IsDevelopment())

            {

                app.UseDeveloperExceptionPage();

                app.UseMigrationsEndPoint();

            }

            else

            {

                app.UseExceptionHandler("/Error");

                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.

                app.UseHsts();

            }

 

            app.UseHttpsRedirection();

            app.UseStaticFiles();

            if (!env.IsDevelopment())

            {

                app.UseSpaStaticFiles();

            }

 

            app.UseRouting();

 

            app.UseAuthentication();

            app.UseIdentityServer();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>

            {

                endpoints.MapControllerRoute(

                    name: "default",

                    pattern: "{controller}/{action=Index}/{id?}");

                endpoints.MapRazorPages();

            });

 

            app.UseSpa(spa =>

            {

                // To learn more about options for serving an Angular SPA from ASP.NET Core,

                // see https://go.microsoft.com/fwlink/?linkid=864501

 

                spa.Options.SourcePath = "ClientApp";

 

                if (env.IsDevelopment())

                {

                    spa.UseAngularCliServer(npmScript: "start");

                    spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");

                }

            });

            //--------</ Configure() >-----

        }

    }

}

 

An unhandled exception occurred while processing the request.

SocketException: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte.

System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)

HttpRequestException: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte. (localhost:4200)

System.Net.Http.ConnectHelper.ConnectAsync(Func<SocketsHttpConnectionContext, CancellationToken, ValueTask<Stream>> callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)

HttpRequestException: Failed to proxy the request to http://localhost:4200/, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://localhost:4200/.

The underlying exception message was 'Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte. (localhost:4200)'.Check the InnerException for more details.

Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task<Uri> baseUriTask, CancellationToken applicationStoppingToken, bool proxy404s)

 

 

HttpRequestException: Failed to proxy the request to http://localhost:4200/, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://localhost:4200/. The underlying exception message was 'Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte. (localhost:4200)'.Check the InnerException for more details.