views:

598

answers:

1

Hello,



Q1 - If character ‘C’ is saved into viewstate, then just before the page is rendered,Asp.Net serializes ‘C’(along with other data) into Base64 string. If on postback I issue the following code:


protected void Page_Load(object sender, EventArgs e)
{
     TextBox1.Text = "ABCDEF";
     if (IsPostBack)
     {
          string viewStateString=Request["__VIEWSTATE"];

          byte[] stringBytes = Convert.FromBase64String(viewStateString);

          for (int i = 0; i < stringBytes.Length; i++)
          {
              if(stringBytes[i] == 67)
                    Label1.Text = ”deserialization successful”; 
          }               
     }
 }


, then FromBase64String() should convert serialized data back into their original format. Thus, one of ‘stringBytes’ fields should contain a decimal value 67( which represents ASCII character C) .But that doesn’t seem to be the case. Any ideas what I’m doing wrong?


Q2 - Since String represents a set of Unicode characters, I assume that in the above example when “ABCDEF” is deserialized from the viewstate, each character in “ABCDEF” string is represented with two elements of a ‘stringBytes’ array?



bye



EDIT:

I must apologize for not mentioning that I did set enableViewStateMac to false in Page tag, but it still didn't work

+2  A: 

In addition to Base64 encoding ASP.NET encrypts that data. If you decode it without decrypting, you won't get initial values.

Koistya Navin
This is correct. To prevent cross site scripting or blind posting attacks, the ViewState is encrypted.
John Gietzen