tags:

views:

107

answers:

3

Hi,

If I have a small microsite and on the first page I want to ensure that the user cannot jump to a non secure page between (e.g. 2 or 3), what would be the best way to implement this? The next page can only be seen if the user sets a certain item in a drop down box.

My first thought is cookies. If the user goes to the second page and the cookie's value is null, then there is a redirect to a failure page. If the user chooses the right value, the cookie's value is set to being a success. Would this approach work if I send a link on the 2nd page to a friend on another PC?

Is there a better way? Thanks

A: 

Cheap, downa and dirty? The cookie or session value work. Neither are reliable long term.

If you are making it so a user can only see certain info after selecting a drop down, you can hide it in a panel and only show that panel when the drop down is selected. This is the most useful if you do not mind the user having to select from drop down each time. You can use this with a cookie, as well, if you want the user to be able to see the data without selecting the drop down.

Hidden in the same page (drop down in one panel, info in another), you can keep it hidden perpetually.

If this has to be a second page, you can also put the page in another directory, and then put a web.config file in there that requires log in. You can then make it like a "log in" by "logging in" every person that answers. You end up using the Membership bits, but they are not hooked up to anything.

Gregory A Beamer
That's worse, no? Unless by hiding you mean making the control's Visible property false. If you're just hiding via CSS, the user just needs to view source to see what they're not supposed to see.
Robert C. Barth
As this is an ASP.NET form, I am talking about Panel1.Visible = true; Panel2.Visible = false. Not CSS. It is thinking more like windows forms than ASP.NET, but that is the model MS has provided us. You then flip the visible when the form is submitted. Now, this is not very AJAX friendly. ;-)
Gregory A Beamer
A: 

Cookies are not a good idea for this for one specific reason. They are under the control of the user, not you.

If a user has cookies disabled (globally or just for your site), they won't be able to get to page 2 now matter how many times they've read page 1.

In addition, if they know what your cookie contains (i.e., it's not encrypted), they can easily create it themselves or forward the method to a friend to get them to create it.

Regarding your question on whether you could send the page 2 link to someone else, cookies belong to the computer. That means the "someone else" would almost certainly not have the correct cookie for properly viewing page 2: they'd get an error.

We implemented a similar scheme (many years ago so there may be better ways to do it now). It involved storing a special "one-time" key when delivering page 1 to an IP address. The links in that page 1 were modified to include this key as an argument so that, when you requested page 2, the key was sent through as well.

The keys had a 30-minute lifetime (configurable but we ended up at 30 minutes). In order for us to deliver a page 2, the request had to come from the same IP address and have the proper key.

This prevented forwarding of links to other places and ensured the links had limited lifetimes.

Whether that's a viable solution for you is a question only you can answer. I know we got a few complaints from people who bought up page 1, then went out for a coffee. When they got back, their attempt to access page 2 was unsuccessful. We fixed this by simply redirecting them to page 1 with a suitable error message that their key had timed out.

Not perfect but, since the users were educated as to why it was happening, they understood its necessity.

paxdiablo
A: 

If I understand your question correctly then the link you send to your friend will not work as they will not have the cookie stored in their browser memory or on their machine. This would also be true if you stored the value in Session as they will be creating their own new session when they opened the link.

To get this kind of behaviour when sharing links you will need to pass the value in a querystring i.e. when you select the desired option on page 1 and sublit the form the postback takes the selected option and then redirects to page 2 with option appended to the url as a querystring value.

Andy Rose