I found myself needing to encrypt/decrypt multiple querystring parameters quite often so I created a simple method that will decrypt the values and set them to strings, maybe this will help.
Remember, as Corsair commented, you must convert your integers to strings before encrypting.
// Here's the method (I put this in my BasePage so all pages have access to this).
Code:
public string GetDecryptedValue(string queryString)
{
// Decrypt the query string
NameValueCollection collection = DecryptQueryString(Request.QueryString.ToString());
if (collection == null)
{
return null;
}
else
{
// Get string value
string value = collection[queryString];
if (string.IsNullOrEmpty(value))
{
return null;
}
else
{
return value;
}
}
}
// Here's a sample of using it.
Code:
// Query string values
string field1 = "value1";
string field2 = "value2";
string field3 = "value3";
// Encrypt the query strings
string Url = "page.aspx" + EncryptQueryString("f1=" + field1 + "&f2=" + field2 + "&f3=" + field3);
// Decrypt query strings
string field1 = GetDecryptedValue("f1");
string field2 = GetDecryptedValue("f2");
string field3 = GetDecryptedValue("f3");
Hope this helps,
Ronnie