ASP.NET security works behind the scenes to protect your data.
Encryping Query string’s avoid the leakage of sensitive page
Information.For encrypting Query string’s we need hexa decimal
Encryption’s.
Plaese see the below Method,
public EncryptedQueryString(string encryptedData)
{
// Decrypt data passed in using DPAPI
byte[] RawData = HexEncoding.GetBytes(encryptedData);
byte[] ClearRawData = ProtectedData.Unprotect(
RawData, null, DataProtectionScope.LocalMachine);
string StringData = Encoding.UTF8.GetString(ClearRawData);
// Split the data and add the contents
int Index;
string[] SplittedData = StringData.Split(new char[] { ‘&’ });
foreach (string SingleData in SplittedData)
{
Index = SingleData.IndexOf(‘=’);
base.Add(
HttpUtility.UrlDecode(SingleData.Substring(0, Index)),
HttpUtility.UrlDecode(SingleData.Substring(Index + 1))
);
}
}
In aspx page,
<form id=”form1″ runat=”server”>
<div>
Enter some data here: <asp:TextBox runat=”server” ID=”MyData” />
<br />
<br />
<asp:Button ID=”SendCommand” runat=”server” Text=”Send Info”
OnClick=”SendCommand_Click” />
</div>
</form>
for ex, in SendCommand event,
protected void SendCommand_Click(object sender, EventArgs e)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add(“MyData”, MyData.Text);
QueryString.Add(“MyTime”, DateTime.Now.ToLongTimeString());
QueryString.Add(“MyDate”, DateTime.Now.ToLongDateString());
Response.Redirect(“Recipient.aspx?data=” +
QueryString.ToString());
}
In destination Page load,
protected void Page_Load(object sender, EventArgs e)
{
// Deserialize the encrypted query string
EncryptedQueryString QueryString =
new EncryptedQueryString(Request.QueryString["data"]);//Method we used
// Write information to the screen
StringBuilder Info = new StringBuilder();
foreach (String key in QueryString.Keys)
{
Info.AppendFormat(“{0} = {1}<br>”, key, QueryString[key]);
}
QueryStringLabel.Text = Info.ToString();
}
Hope,this helps
Happy Coding.
Hi,Great article dude! i am Fed up with using RSS feeds and do you use twitter?so i can follow you there:D.
PS:Have you thought to be putting video to your web site to keep the readers more entertained?I think it works.Kind regards, Orville Chatampaya
I never, ever imagined I would have to know this thank goodness for the internet, right?