public JObject PostBackStates()
{
JObject xState = null;
if (Page.IsPostBack)
{
string state = HttpContext.Current.Request.Form["X_STATE"];
string xstateURI = HttpContext.Current.Request.Form["X_STATE_URI"];
if (!String.IsNullOrEmpty(state))
{
state = String.IsNullOrEmpty(xstateURI) ? DecodeFrom64(state) : HttpUtility.UrlDecode(state);
}
state = String.IsNullOrEmpty(state) ? "{}" : state;
xState = JObject.Parse(state);
}
return xState;
}
private string DecodeFrom64(string encodedData)
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
return System.Text.UTF8Encoding.UTF8.GetString(encodedDataAsBytes);
}
private string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes = System.Text.UTF8Encoding.UTF8.GetBytes(toEncode);
return System.Convert.ToBase64String(toEncodeAsBytes);
}