Share via

API issue on the server

Peter_1985 3,151 Reputation points
2026-03-11T06:10:53.63+00:00

Hi,

No similar issue when calling the project. Why does it appear when going to "https://localhost:7060/swagger/index.html"?

User's image

Developer technologies | ASP.NET | ASP.NET API
{count} votes

2 answers

Sort by: Most helpful
  1. Damien Pham (WICLOUD CORPORATION) 1,525 Reputation points Microsoft External Staff Moderator
    2026-03-12T10:24:25.5666667+00:00

    Hello @Peter_1985 ,

    Thank you for the snippet. From the screenshot, you have

    if (app.Environment.IsProduction())  
    {      
    app.UsePathBase("/webapp1"); // Must match your IIS alias  
    }
    

    It is configured in Production environment, but the swaggerUI is configured in Development environment. This is likely why you only get the error when go to https://localhost:7060/swagger/index.html

    To fix this, you can configure the environment to Production for both.

    Hope you can resolve your issue. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide provide feedback.      

    Thank you.   

    0 comments No comments

  2. Q&A Assist
    2026-03-11T06:11:20.03+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The screenshot shows that Swagger UI loads, but it can’t fetch the OpenAPI document at /swagger/v1/swagger.json (NetworkError). This usually means the API is running and reachable, but the Swagger endpoint itself is misconfigured or not available at that path.

    Typical causes in ASP.NET Core Web API:

    1. Swagger middleware not mapped for the environment
      • In Program.cs, Swagger is often only enabled in Development:
         if (app.Environment.IsDevelopment())
         {
             app.UseSwagger();
             app.UseSwaggerUI();
         }
      
      If the app is running under a different environment (e.g., Production), /swagger/v1/swagger.json won’t exist, and Swagger UI will show a network error.
      • Fix: Either run the app with ASPNETCORE_ENVIRONMENT=Development or move app.UseSwagger(); app.UseSwaggerUI(); outside the IsDevelopment block if Swagger should always be available.
    2. Wrong route or document name
      • If SwaggerGen is configured with a different document name or route, the UI might still be pointing to /swagger/v1/swagger.json while the actual JSON is at another URL.
      • Fix: Ensure the document name in AddSwaggerGen matches the one used in UseSwaggerUI, for example:
         builder.Services.AddSwaggerGen(c =>
         {
             c.SwaggerDoc("v1", new() { Title = "WebApp1", Version = "v1" });
         });
         
         app.UseSwagger();
         app.UseSwaggerUI(c =>
         {
             c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApp1 v1");
         });
      
    3. HTTPS/port mismatch
      • If the app is actually listening on a different port or scheme than the one Swagger UI is using, the fetch will fail.
      • Fix: Confirm the app is running on https://localhost:7060 and that no reverse proxy or different port is used. Adjust launch profile or Swagger endpoint accordingly.
    4. Middleware order or startup failure
      • If there’s an exception during startup before UseSwagger runs, the JSON endpoint won’t be available even though the browser still shows a cached or partial UI.
      • Fix: Check application logs/console output for startup errors and ensure app.UseSwagger() is called before app.UseAuthorization()/app.MapControllers().

    Because direct calls to the API work, focus on verifying that the Swagger JSON endpoint exists and matches the URL configured in UseSwaggerUI, and that Swagger middleware is enabled for the environment where the app is running.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.