I have a MVC Action Method which is being hit twice if the request takes time to complete. On checking chrome console network log and fiddler, the request is being sent only once from the JS.
In the diagram below, I'm facing this issue with Approach 1. However, it works fine if I do it with Approach 2.
What’s happening with Approach 1 (failure):
JShitsMVC Actionwithwindow.location.href.- Ideal scenario as per code
MVC Action(Time taking process)- Calls
Service Method 1 - Calls
Service Method 2 - Redirects to the confirmation/final page.
- Calls
- What actually happens
MVC Action(Time taking process)- Calls
Service Method 1 - Calls
Service Method 2 - Waits for approximately 4 minutes (Unable to determine the reason)
- Calls
MVC Actionagain - Validation fails and response is redirected to error page since the action method is being called twice with same parameters.
- Calls
What’s happening with Approach 2 (success):
- Split the
MVC Actioncalls into two, 1 and 2 JShitsMVC Action 1usingAjaxMVC Action 1- Calls
Service Method 1 - Responds with the URL to
MVC Action 2 - JS receives
MVC Action 1response and callsMVC Action 2usingwindow.location.href
- Calls
MVC Action 2- Calls
Service Method 2 - Redirects to the confirmation/final page successfully.
- Calls
Even though I’ve found a probable solution with Approach 2, I can’t understand why Approach 1 fails.
The main points that bother me are:
- Why is the
MVC Actionbeing called twice even if the process takes long time to complete? Couldn’t it just have timed-out? - Why there is a gap of approximately 4 minutes before the second call happens?
Edit: I've tried it on Chrome 45.0.2454.101 m, Firefox 40.0.3, IE (7, 8, 9, 10) without any success.
ASP.NET MVC 2.0
.NET 4.0
Note: I've looked at other similar problems (google/SO) but it didn't help me.
