开发者

How to use ASP.NET with "Redirect after POST" pattern? [Edited]

开发者 https://www.devze.com 2023-01-13 02:25 出处:网络
I\'m trying to implement Redirect After Post for the first time in ASP.NET.Assuming my business objects may take several seconds to a minute to complete, in what order, and what syntax do I use?

I'm trying to implement Redirect After Post for the first time in ASP.NET. Assuming my business objects may take several seconds to a minute to complete, in what order, and what syntax do I use?

For example:

  1. User POST's

  2. Server issues Server.Transfer or Response.Redirect

  3. Server does something that takes a 开发者_Python百科minute or two Thread.Sleep

What is the best way to handle this type of situation?


In this case, it is probably best to just stick with Response.Redirect() so that the user's client is issued a redirect, rather than Server.Transfer() which performs a purely server-side redirect to a different context.

Regarding the process which requires the user to wait, you may want to use some sort of asynchronous implementation where the time-consuming operation is placed in a background thread; meanwhile the user, instead of waiting on a blank loading screen, is given Response.Redirect() to a "Processing" page that polls the server for completion of the current operation and updates the user. For added polish, consider implementing something like Facebook's image uploader which overlays a progress bar in the corner of the screen while the user continues normal use of the website.


From what I can see you need to do:

  1. User POSTs form to server script
  2. Server does something that takes a minute or two using Thread.Sleep
  3. Server issues a Response.Redirect

However, the obvious drawbacks here are that the user is kept waiting whilst the server does some work (two minutes is a long delay period, they may well assume that something has gone wrong), and possibly you might hit a HTTP request time out on the browser.

In terms of code, it's pretty straightforward:

  1. This is a standard <FORM METHOD="POST"> code
  2. Do whatever you need to do, can't see why you would need Thread.Sleep at the moment; wouldn't you want to redirect to happen as soon as your server side processing has completed?
  3. Call Response.Redirect("mypage.aspx") to perform the GET

Does that help?

0

精彩评论

暂无评论...
验证码 换一张
取 消