Error in Encryption and Decryption

Posted by Saritha.rajeshkumar under C# on 5/26/2011 | Points: 10 | Views : 900 | Status : [Member] | Replies : 1
hi,
this is saritha
iam getting the Error System.IndexOutOfRangeException: Index was outside the bounds of the array.
for (location = arrIndMsg[2].ToString().Trim();) this line.
private void BindData1()
{
if (!IsPostBack)
{
string strReq = "";
strReq = Request.RawUrl;
strReq = strReq.Substring(strReq.IndexOf('?') + 1);
strReq = DecryptQueryString(strReq);

//Parse the value... this is done is very raw format.. you can add loops or so to get the values out of the query string...
string[] arrMsgs = strReq.Split('&');
string[] arrIndMsg;
string keyskills = "", location = "", category = "", experience="";

arrIndMsg = arrMsgs[0].Split('=');
keyskills = arrIndMsg[1].ToString().Trim();//get the jobId

arrIndMsg = arrMsgs[0].Split('=');
location = arrIndMsg[2].ToString().Trim();

arrIndMsg = arrMsgs[0].Split('=');
category = arrIndMsg[3].ToString().Trim();

arrIndMsg = arrMsgs[0].Split('=');
experience = arrIndMsg[4].ToString().Trim();

Lblkeyskills.Text = keyskills;
Lbllocation.Text = location;
Lblcategory.Text = category;
Lblexp.Text = experience;

Session["OrganisationName"] = Lblorgname.Text.Trim();
Panel2.Visible = true;
DataList1.Visible = true;
jb.Skills = Lblkeyskills.Text;
jb.Location = Lbllocation.Text;
jb.jobcategory = Lblcategory.Text;
jb.Experience = Lblexp.Text;
DataList1.DataSource = jb.showJobSeekerSearchjobs();
DataList1.DataBind();
Lblorgname.Text = jb.OrganisationName;
Lblmsg.Visible = false;
if (DataList1.Items.Count.ToString() == "0")
{
Lblmsg.Visible = true;
Lblmsg.Text = " Sorry No Jobs Found of This Type !";
Panel2.Visible = false;
}

}
}




Responses

Posted by: Ndebata on: 5/26/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Try to replace these part in you code. You are splitting the string by = and accesing a index more than that of array index.
You handle it safely.

arrIndMsg = arrMsgs.Length >0 ? arrMsgs[0].Split('='):null;

keyskills = arrIndMsg!=null && arrIndMsg.Length > 1 ? arrIndMsg[1].ToString().Trim() : "";

arrIndMsg = arrMsgs.Length > 1 ? arrMsgs[1].Split('=') : null;
location = arrIndMsg != null && arrIndMsg.Length > 1 ? arrIndMsg[1].ToString().Trim() : "";

arrIndMsg = arrMsgs.Length > 2 ? arrMsgs[2].Split('=') : null;
category = arrIndMsg != null && arrIndMsg.Length > 1 ? arrIndMsg[1].ToString().Trim() : "";

arrIndMsg = arrMsgs.Length > 3 ? arrMsgs[3].Split('=') : null;
experience = arrIndMsg != null && arrIndMsg.Length > 1 ? arrIndMsg[1].ToString().Trim() : "";


Thanks,
Debata

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response