Friday, March 16, 2012

Passing Action Parameter

Hi,

I have used parameters with certain situations so far. For example, i want to display a product whose categoryID equals 3 and productID equals 345 and then these values are sent to the display page like < display.aspx?categoryID=3&productID=345 >. After that, this product is found from the database and is displayed. However, i have seen some websites which uses a parameter system with multiple actions. I mean there are some actions and also these type parameters. Here are some examples;

page.aspx?action=sendPMTo&userID=123 //send private message to the user whose id = 123

page.aspx?action=readPMs&messageID=124 //read private message whose id = 124

page.aspx?action=displayProduct&categoryID=1&productID =2 //display the product whose category = 1 and id = 2

There is a blank page and we use it for several actions. I think we can do this with if-else blocks, can't we? If we can't how can we do? Also if we do like this how about performance considertions of the application.

Thanks...

You'd probably be better with a case statement rather than an if-else block. Another consideration is that your application won't be secure since people would manually be able to change the strings and then you can have one rogue user sends PMs to everyone in the database. You'd probably want to encrypt that querystring if that's how you wanted to use your application.

As for how to do it, just do something like the following:

SelectCase Request.QueryString("action")

Case"sendPMTo"

'...code

'...Other case statements

EndSelect

0 comments:

Post a Comment