Starts in:
2 DAYS
4 HRS
7 MIN
30 SEC
Starts in:
2 D
4 H
7 M
30 S
Open Closed

Invalid URI: The hostname could not be parsed. OpenIddict #5661


User avatar
0
ademaygun created

Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v7.1.1
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I developed a new project in Abp and ran it on our test servers. However, when I deployed it to production environments, I started encountering this error. I have checked all the URLs related to OpenIdDict, but couldn't find any issues. Why do you think I am getting this error? (I have checked the DNS, and there doesn't seem to be a problem there either)

2023-08-25 11:42:44.908 +03:00 [ERR] Connection id "0HMT58T053R06", Request id "0HMT58T053R06:00000001": An unhandled exception was thrown by the application.
System.UriFormatException: Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString, UriKind uriKind)
   at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers.ResolveRequestUri.HandleAsync(ProcessRequestContext context)
   at OpenIddict.Validation.OpenIddictValidationDispatcher.DispatchAsync[TContext](TContext context)
   at OpenIddict.Validation.OpenIddictValidationDispatcher.DispatchAsync[TContext](TContext context)
   at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandler.HandleRequestAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)


20 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hiello ademaygun,

    Can you please share your deployed application appsettings.json file.

    There might be some misconfiguration related to URL's

    Thank you, Anjali

  • User Avatar
    0
    enes.koroglu created

    Hi Anjali_Musmade,

    You can find below:

    {
      "Settings": {
        "Abp.Mailing.DefaultFromAddress": "noreply.information.myprojectname@mydomain.com",
        "Abp.Mailing.DefaultFromDisplayName": "MyCompany myprojectname"
      },
      "App": {
        "SelfUrl": "https://myprojectname-api.mydomain.com",
        "AngularUrl": "https://myprojectname.mydomain.com",
        "CorsOrigins": "https://*.myprojectname.com,http://localhost:4200,https://myprojectname.mydomain.com",
        "RedirectAllowedUrls": "https://myprojectname.mydomain.com",
        "DisablePII": "true",
        "HealthCheckUrl": "/health-status"
      },
      "ConnectionStrings": {
        "Default": "Host=mydb.mydomain.com;Port=5432;Database=myprojectname;User ID=myprojectname_app;Password=*******;"
      },
      "AuthServer": {
        "Authority": "https://myprojectname-api.mydomain.com",
        "RequireHttpsMetadata": "true",
        "SwaggerClientId": "myprojectname_Swagger"
      },
      "StringEncryption": {
        "DefaultPassPhrase": "*************"
      }
    }
    
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello ademaygun,

    We tried deploying the application with v7.1.1, but could not be able to reproduce the issue. Also Checked your appsettings.json ,it looks fine. could you please elaborate more on your question.

    Thanks, Anjali

  • User Avatar
    0
    ademaygun created

    Hi Anjali_Musmade, The same error is appearing in the logs every 2 seconds on its own. We've turned off Healthcheck, so it's not the cause. We've checked all of our URLs, and there doesn't appear to be any issue. We don't experience this problem in the test environment; it only occurs in the production environment

  • User Avatar
    0
    alper created
    Support Team Director

    I assigned this to @maliming

  • User Avatar
    0
    enes.koroglu created

    Hi @maliming

    We are trying to go live and this mistake preventing us. We need urgent support.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I checked the error, and it seems to occur on these lines.

    https://github.com/openiddict/openiddict-core/blob/dev/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs#L120-L121

    Can you check the HttpRequest info of your production environment

    You can add a middleware to output the HttpRequest info to logs.

  • User Avatar
    0
    enes.koroglu created

    Can you please share a demo or a sample code?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    System.UriFormatException: Invalid URI: The hostname could not be parsed.

    You can also share the context logs when this exception occor

    
    app.Use(async (httpContext, next) =>
    {
        var logger = httpContext.RequestServices.GetRequiredService<ILogger<YourModule>>();
    
        try
        {
            //BaseUri: new Uri(request.Scheme + Uri.SchemeDelimiter + host + request.PathBase, UriKind.Absolute),
            // RequestUri: new Uri(request.GetEncodedUrl(), UriKind.Absolute)),
            logger.LogError("BaseUri: " + httpContext.Request.Scheme + Uri.SchemeDelimiter + httpContext.Request.Host + httpContext.Request.PathBase);
            logger.LogError("RequestUri: " + httpContext.Request.GetEncodedUrl());
    
        }
        catch (Exception e)
        {
            logger.LogError(e, e.Message);
        }
    
        await next(httpContext);
    });
    app.UseAuthentication();
    app.UseAuthorization();
    
  • User Avatar
    0
    enes.koroglu created

    I will also try your logging code and share result but i tried a method and results are like below. Can you please check below log.

    Valid URL: https://myproject-api.ekol.com/api/account-admin/settings/two-factor Invalid URL (HTTP404): https://myproject-api.ekol.com/swagger/v1/api/account-admin/settings/two-factor

    2023-08-28 16:39:50.203 +03:00 [INF] Request:
    Protocol: HTTP/1.1
    Method: PUT
    Scheme: https
    PathBase: 
    Path: /swagger/v1/api/account-admin/settings/two-factor
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Connection: keep-alive
    Host: myproject-api.ekol.com
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
    Accept-Encoding: gzip,deflate,br
    Content-Type: application/json
    Cookie: [Redacted]
    Content-Length: 210
    X-Real-IP: [Redacted]
    X-Forwarded-For: [Redacted]
    X-Forwarded-Proto: [Redacted]
    2023-08-28 16:39:50.206 +03:00 [ERR] An unhandled exception has occurred while executing the request.
    System.UriFormatException: Invalid URI: The hostname could not be parsed.
       at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
       at System.Uri..ctor(String uriString, UriKind uriKind)
       at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers.ResolveRequestUri.HandleAsync(ProcessRequestContext context)
       at OpenIddict.Validation.OpenIddictValidationDispatcher.DispatchAsync[TContext](TContext context)
       at OpenIddict.Validation.OpenIddictValidationDispatcher.DispatchAsync[TContext](TContext context)
       at OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandler.HandleRequestAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
       at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
       at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware.InvokeInternal(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
    
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you share how you deployed your application? Can you share the steps to reproduce the issue?

    It's hard for me to confirm the problem now, but I can confirm that this is a deployment problem. It has nothing to do with the code

  • User Avatar
    0
    enes.koroglu created

    We have deployment scripts nearly same (except server name and build directory). If you share email address, i can send build scripts for both environment.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    liming.ma@volosoft.com

  • User Avatar
    0
    enes.koroglu created

    Send deployment scripts to mail address

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi Can you share your project source code? Include the steps that I can reproduce locally.

  • User Avatar
    0
    ademaygun created

    Hi Maliming, The error is still occurring.Unfortunately, we cannot share the source code. If possible, can we meet via Google Meet? Can you share your Gmail address and your available time with us

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I believe I can reproduce the problem in your computer during the meeting, but I still need to find the cause.

  • User Avatar
    0
    ademaygun created

    We've identified the source of the problem. We have an Nginx server in the DMZ, and other requests are also coming to this project. In the past, another Abp project with version 5.1.4 (IdentityServer) used to handle other requests, but it didn't throw any errors.

    The request causing the error: (nginx access log) X.X.X.X - - [05/Sep/2023:16:07:47 +0300] "GET /swagger HTTP/1.1" 500 177 "https://[A.B.C.D]/" "Go-http-client/1.1"

    X.X.X.X is our test server, which has Grafana installed and sends these requests.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I'm not familiar with nginx, have you solved your problem?

  • User Avatar
    0
    ademaygun created

    yes, thanks for your attention

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06