Hello,
I understand you’re seeing unexpected request paths in your ASP.NET Core Web API logs — sometimes showing as /:undefined or Struts-style URLs like /struts2-showcase/.... You also mentioned that locally you see only expected paths (e.g., /swagger/index.html), but in Test/Prod, the logs include these strange entries.
I think here’s what’s going on:
- These unusual paths are not generated by your application.
- They come from external traffic — often automated bots, vulnerability scanners, or misconfigured clients probing your public endpoints.
- Paths like
/struts2-showcase/...are typically attempts to find and exploit known vulnerabilities in Apache Struts (which your app isn’t using). -
/:undefinedusually originates from malformed requests, where the client substituted an uninitialized value in the URL. - Locally you don’t see them because your development machine is not exposed to the public internet.
Why HttpContext.Request.Path shows them
HttpContext simply reports the exact path that the client requested — even if it’s invalid or meaningless. In other words, your logging middleware is doing its job correctly.
Recommended Actions
- Fix middleware ordering
Correct ordering ensures HttpContext is populated consistently before logging.
For example:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "My Demo API (V 1.0)");
});
// Redirect root to Swagger
app.Use(async (context, next) =>
{
if (context.Request.Path == "/")
{
context.Response.Redirect("/swagger/index.html");
return;
}
await next();
});
// Early filter for unwanted paths
app.Use(async (context, next) =>
{
var path = context.Request.Path.Value?.ToLowerInvariant() ?? "";
if (path == "/:undefined" || path.Contains("struts2") || path.EndsWith(".action"))
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync("Not Found");
return;
}
await next();
});
// Logging middleware
app.UseMiddleware<LoggerHelper>();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseHealthChecks("/health", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
This:
- Serves Swagger by default
- Filters bot/malformed requests early
- Runs logging after routing/auth context is established
- Filter logs
If you want to keep logging everything but avoid polluting logs, add logic in LoggerHelper to mark or skip suspicious paths.
- Block at the edge
For best performance, configure URL filtering at:
- IIS: URL Rewrite rules
- Nginx/Apache:
locationblocks or rewrite rules - Azure App Gateway / WAF: custom rules matching suspicious patterns
This prevents bad requests from ever reaching your app.
Conclusion
The / : undefined paths are caused by external, malformed requests and are expected on internet-facing APIs. Your application is not generating them. The resolution is to:
- Ensure middleware order is correct for consistent logging.
- Filter or tag suspicious requests in middleware.
- Optionally block these requests at the network/proxy layer.
Hope this helps.