简体   繁体   中英

What is the proper way to handle several automatic redirects?

I have a website that basically allows customers to build a cart with an item that can be configured. A user will pick an item, and they'll be prompted to pick the first option they want, they get sent to the second step where they pick their second option, etc.

The number of steps and the number of options are variable, as they are defined by the client. Usually the item only has 2-3 steps with 5-10 options. However, in order to make it faster for the customer, if there is only one option available for the given step, it will automatically be chosen and the user will be sent to the next step.

A client decided to set up an item with 10+ steps with only one option for each step. This results in the entire process automatically choosing everything. FireFox doesn't like this, as it gives the error

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

(I haven't checked IE or Chrome, although it probably gives similar errors).

What's the best way to fix this?

Right now the process is basically

  1. User picks item
  2. User picks option if there is more than one option available. Otherwise the website does step 3 itself.
  3. POST to add the option to the cart
  4. Redirect to Page.aspx?step=#
  5. Repeat step 2-4 as many times as necessary

Is there any change I can make to the code or page so that FireFox doesn't think I'm in an endless loop?

I am surprised that you get an endless redirect error if # is different each time, but either way, this doesn't seem like the best architecture. Basically, if the code decides a step can be done automatically, it instantly redirects to the same page with the new step number?

Why don't you just have your code do that without redirecting, increment the page number in the server code as needed, and show them the right step directly, without having to redirect?

Whatever is happening when you POST at each step I would think you can accomplish just as easily in code without actually having to do a new post.

I'm guessing something like this would work:

  1. Read Step # from query string into local variable
  2. Load data from database passing in the local step variable
  3. If data only contains one option then:
    (3.1) Store option
    (3.2) increment local step variable
    (3.3) goto 2

  4. Load page with data from step 2


How does your code handling someone skipping options and entering Page.aspx?step=10 into the address bar when they are on Page.aspx?step=1?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM