Saturday, March 24, 2012

Passing variables - best practices

I want to pass an ID variable from one page to the next and I want to prevent the user from messing with it or trying to guess new IDs. The possible options I've thought of are:

1) URL Variable - Plain Text
2) URL Variable - Custom Encrypt / Decrypt method
3) Session variable

This seems like it would be a very common task, can anybody tell me what they feel the best way to tackle this is?

ThanksIf the users don't want to guess, then go for Session! I would go for Encrypt/Decrypt also, but it has performace problem as we have to encrypt and decrypt the values!
You could either use session variables or access variables of page using Page Context.

However, for accessing variables using Context, you need to use Server.Transfer but not Response.Redirect for redirecting.

pageA.aspx
--
public int id = 20;

PageB.aspx
--
PageA prevPage = (PageA) Context.Handler;

// you could get the id from the previous page
int id = prevPage.id;

HTH
Thanks for the feedback, is there a good encrypt / decrpt method or should I try to make something up myself?
See any thing is useful or you like in below link

http://www.gotdotnet.com/community/usersamples/Default.aspx?query=Encrypt

0 comments:

Post a Comment