MVC Action called twice

不羁的心 提交于 2019-12-10 10:10:52

问题


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):

  1. JS hits MVC Action with window.location.href.
  2. Ideal scenario as per code
    • MVC Action (Time taking process)
      • Calls Service Method 1
      • Calls Service Method 2
      • Redirects to the confirmation/final page.
  3. 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 Action again
      • Validation fails and response is redirected to error page since the action method is being called twice with same parameters.

What’s happening with Approach 2 (success):

  1. Split the MVC Action calls into two, 1 and 2
  2. JS hits MVC Action 1 using Ajax
  3. MVC Action 1
    • Calls Service Method 1
    • Responds with the URL to MVC Action 2
    • JS receives MVC Action 1 response and calls MVC Action 2 using window.location.href
  4. MVC Action 2
    • Calls Service Method 2
    • Redirects to the confirmation/final page successfully.

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:

  1. Why is the MVC Action being called twice even if the process takes long time to complete? Couldn’t it just have timed-out?
  2. 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.

来源:https://stackoverflow.com/questions/33013136/mvc-action-called-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!