Issue with Webhook-Enabled Telegram Bot and Ngrok

Using ASP.NET Core 3.1, a Telegram bot that employs webhooks and works with ngrok runs perfectly in Visual Studio but returns a 502 Bad Gateway when executed as a standalone .exe. What could be causing this error?

In a similar project, I encountered a similar discrepancy between running in Visual Studio and as a standalone .exe. I found that the issue was caused by determining the correct binding addresses for Kestrel. When running the .exe, ensuring that the application explicitly specified the appropriate URL and port was crucial. Additionally, checking the environment variables and validating that the ngrok URL was correctly passed and accessible can make a significant difference. This approach ultimately resolved the 502 Bad Gateway error in my implementation.