CodexBloom - Programming Q&A Platform

Visual Studio 2022 - implementing Web API Request Timing Out When Using Swagger UI

👀 Views: 1136 💬 Answers: 1 📅 Created: 2025-06-13
asp.net-core swagger visual-studio C#

I'm currently working with a frustrating scenario with my ASP.NET Core Web API project in Visual Studio 2022. Whenever I try to test my endpoints via Swagger UI, the requests seem to time out after a few seconds, even though the server is running correctly and I can hit the endpoints directly through Postman without any issues. I've already verified that the application is not throwing any exceptions and that the endpoints are correctly configured. Here’s a snippet of my `Startup.cs` where I configure Swagger: ```csharp public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); } ``` I’ve also tried increasing the `HttpClient` timeout settings in my service layer, but that didn’t help either. Here’s what I set: ```csharp services.AddHttpClient<IMyService, MyService>(client => { client.Timeout = TimeSpan.FromSeconds(30); }); ``` Despite these efforts, when I make a request through Swagger UI, I get the following behavior in the browser console: ``` behavior: Request failed: timeout of 5000ms exceeded ``` This timeout is set in Swagger UI itself, but I can’t seem to find a way to change it. I suspect it might be related to the way Swagger is handling the requests or perhaps a misconfiguration in my API routes. Any advice on how to resolve this or even where to look for further troubleshooting would be greatly appreciated!