500 - The request timed out
If your web app has any piece of code that takes this long time then move it to a web job instead, at least to avoid any impact on the application scalability.
Create a web job and move the code that takes a long time to it.
Make the web job listen for a queue
In your web app, after the user submit, insert a message with the required details in the queue
If you need to notify the user about the completion of the process, then use SignalR, connect to the hub from your JavaScript, and post a message top it from the web job code, this will notify the user immediately
You are most probably running into the 230-second timeout hardcoded in App Service.
See this question for more:
Azure ASP .net WebApp The request timed out
Try to have that long running task as a WebJob and post the results to a Queue or Table. Or post to a Table/Blob (maybe even Redis if you're reusing the data a lot) and signal with a Queue message.