Base solution for your next web application
Open Closed

Issue on startup file #10127


User avatar
0
Ricavir created
  • product type : Angular
  • product framework : .NET CORE
  • ABP Framework : 5.7

I'm having issues in startup.cs file. The issue is linked with SignalR client connections that are getting 404 failed request. The line causing issues in logs is the following :

app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index.html"; await next(); } });

I don't understand the need of this line. Can you please explain why is it used in the pipeline ? Can I remove it ?

Related log ERROR is :

ERROR 2021-02-25 16:29:15,485 [24 ] AspNetCore.Server.IIS.Core.IISHttpServer - Connection ID "4395513237924216957", Request ID "8000007f-0000-3d00-b63f-84710c7967bb": An unhandled exception was thrown by the application. System.InvalidOperationException: StatusCode cannot be set because the response has already started. at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ThrowResponseAlreadyStartedException(String name) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.set_StatusCode(Int32 value) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_StatusCode(Int32 value) at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_StatusCode(Int32 value) at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher.GetConnectionAsync(HttpContext context) at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher.ProcessSend(HttpContext context, HttpConnectionDispatcherOptions options) at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher.ExecuteAsync(HttpContext context, HttpConnectionDispatcherOptions options, ConnectionDelegate connectionDelegate) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Web.Startup.Startup.<>c.<<Configure>b__5_1>d.MoveNext() in D:\a\1\s\aspnet-core\src\Web.Host\Startup\Startup.cs:line 166 --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context) at Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    This line is added to project when the Single Solution option is selected. When you host your Angular app and server side Host app under the same domain, this line redirects some requets to Angular app's index.html, so Angular app works together with server side Host app.

    Is this the line in Startup.cs:line 166 ? IF you don't need to host Angular app with Host app, you can delete this line.

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas,

    Yes I'm in a single solution and hosting an angular app. Therefore, seems that I need that line :)

    But I'm having a lot of logs about it and it seems to be linked with SignalR disconnections. I already post a question about similar issues in the past... Right now, I'm ignoring these errors.

    The problem is that I noticed a huge CPU consumption on my Azure server due to 404 failed requests on SignalR :

    And the only error logs that I have is the ones about this code line (line 166 in startup.cs).

    I also found this ABP issue that might be the same error : https://github.com/abpframework/abp/issues/1830

    Do you think that it could be linked to the SignalR reconnection startegy on clients (angular app or Xamarin app) ?

    Hope you can help me on that because the risk is high when a lot of users are using the app at the same time.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Do you think that it could be linked to the SignalR reconnection startegy on clients (angular app or Xamarin app) ?

    Probably yes. When SignalR connection returns 404, this line handles the request, so that' why you are seeing it in the logs. Can you get any defaults from Azure side about these 404 errors ? If not, you can send your log file to [email protected] and we can try to investigate it.

  • User Avatar
    0
    Ricavir created

    @ismcagdas, I've sent an email with all details for your investigation.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Thanks, I got the file and will investigate it soon.

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas,

    Did you had time to investigate ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Sorry for the delay, I have replied via email.

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas,

    Tks for your reply, do you have further information to share ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Sorry, not yet but I will inform you via email in a short time.