Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version
Go to top

Post Serialized Objects (Data) in ASP.NET

, 25 Feb 2013
This is helper class to post serialized objects (Data) to other page in asp.net.
PostDataSample-noexe.zip
PostData
PostDataSample.suo
PostDataSample
App_Code
WebUtilities
obj
Properties
PostDataSample.zip
PostDataSample.suo
App_Data
Bin
TripleDESEncryption.dll
WebUtilities.dll
WebUtilities.pdb
bin
Debug
TripleDESEncryption.dll
WebUtilities.dll
WebUtilities.pdb
Debug
ResolveAssemblyReference.cache
TempPE
WebUtilities.dll
WebUtilities.pdb
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using TripleDESEncryption;
namespace WebUtilities
{
	public partial class PostDataHelper
	{		
		private static string SecretKey;
		private static string InitializeVector;
		private static TrippleDESCryptoService des;
		private PostDataHelper.PostData _PostData = new PostDataHelper.PostData();
		private HttpResponse Response;
		private HttpRequest Request;
        /// <summary>
        /// Data
        /// </summary>
		public PostDataHelper.PostData Data
		{
			get
			{
				return this._PostData;
			}
		}
        /// <summary>
        /// Get/Set FormName for data
        /// </summary>
		public string FormName
		{
			get
			{
				return this.Data.FormName;
			}
			set
			{
				this.Data.FormName = value;
			}
		}
        /// <summary>
        /// Static ctor to initialize encryptor
        /// </summary>
		static PostDataHelper()
		{
			PostDataHelper.SecretKey = ConfigurationManager.AppSettings["TripleDESSecretKey"];
			PostDataHelper.InitializeVector = ConfigurationManager.AppSettings["TripleDESIntialzationVector"];			
			PostDataHelper.des = new TrippleDESCryptoService(PostDataHelper.SecretKey, PostDataHelper.InitializeVector);
		}
        /// <summary>
        /// ctor    
        /// </summary>
        /// <param name="request">Current Request</param>
        /// <param name="response">Current Response</param>
		public PostDataHelper(HttpRequest request, HttpResponse response)
		{
			this.Request = request;
			this.Response = response;
		}
        /// <summary>
        /// Reads data posted using same utility
        /// </summary>
		public void ReadPostedData()
		{
			this._PostData = new PostDataHelper.PostData();
			if (this.Request.Form != null && this.Request.Form["__TransferData"] != null)
			{
				foreach (string key in this.Request.Form.Keys)
				{
					this.Data.SetRawData(key, PostDataHelper.des.DecryptData(HttpUtility.HtmlDecode(this.Request.Form[key])));
				}
			}
		}
        /// <summary>
        /// Posts data
        /// </summary>
        /// <param name="Destination"></param>
		public void RedirectWithData(string Destination)
		{
			this.Response.Clear();
			StringBuilder sb = new StringBuilder();
			sb.Append("<html>");
			sb.Append("<body onload='document.forms[\"form\"].submit()'>");
			sb.AppendFormat("<form name='form' action='{0}' method='post'>", Destination);
			foreach (string key in this.Data)
			{
				sb.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", key, HttpUtility.HtmlEncode(PostDataHelper.des.EncryptData(this.Data.GetRawData(key))));
			}
            sb.Append("<noscript>Javascript is disabled, Click submit to proceed.");
			sb.Append("<br/><input type='submit' value='submit'/>");
			sb.Append("</noscript>");
			sb.Append("</form>");
			sb.Append("</body>");
			sb.Append("</html>");
			this.Response.Write(sb.ToString());
			this.Response.End();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ajaynarewade
Systems Engineer TCS
India India
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 25 Feb 2013
Article Copyright 2013 by ajaynarewade
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid