Server Error in '/' Application while Saving Site Settings

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
1/5/2012 9:10:59 AM
Gravatar
Total Posts 149
Partner
mojoPortal Skinning, Custom Development and Support in Italy?
EffectiveWeb.it

Server Error in '/' Application while Saving Site Settings

Hi Joe,

I have just updated to version 2.3.7.6 all installations hosted on my server (and several hosted by providers) and noticed that for two of them I get an error when saving the site settings (even without changing any data).

Any ideas about what I can check/fix to overcome the issue ?

This is the error form mojoPortal System Log:

2012-01-05 15:44:36,371 ERROR 192.168.3.127 - en-US - /Admin/SiteSettings.aspx - mojoPortal.Web.mojoBasePage - 192.168.3.127-en-US - /Admin/SiteSettings.aspx   System.Web.HttpException (0x80004005): The URL-encoded form data is not valid. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.

at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)

at System.Web.HttpRequest.FillInFormCollection()

at System.Web.HttpRequest.FillInFormCollection()

at System.Web.HttpRequest.get_Form()

at System.Web.HttpRequest.get_HasForm()

at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)

at System.Web.UI.Page.DeterminePostBackMode()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

2012-01-05 15:44:36,393 ERROR 192.168.3.127 - en-US - /Admin/SiteSettings.aspx - mojoPortal.Web.Global - 192.168.3.127 /Admin/SiteSettings.aspx Referrer(http://mojoportal.effectiveweb.it/Admin/SiteSettings.aspx) useragent Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0

System.Web.HttpException (0x80004005): The URL-encoded form data is not valid. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.

at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)

at System.Web.HttpRequest.FillInFormCollection()

at System.Web.HttpRequest.FillInFormCollection()

at System.Web.HttpRequest.get_Form()

at System.Web.HttpRequest.get_HasForm()

at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)

at System.Web.UI.Page.DeterminePostBackMode()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

mojoPortal Version 2.3.7.6 MSSQL
Operating System Microsoft Windows NT 6.0.6002 Service Pack 2
ASP.NET Info v4.0.30319 Running in Full Trust

1/5/2012 9:19:43 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

Hi Diego,

This is actually the result of a change from a recent ASP.NET security update. It happens because you have a lot of roles and with the checkboxlists for all the permissions under the permissions tab combinned with all the other form elements it adds up to more than 1000 form elements. The ASP.NET security update set a limit of 1000 and this error happens if there are more than 1000.

I've already fixed this in our source code repository by moving the permissions out of site settings into separate pages to reduce the number of form elements. I will make a new release  very soon with this change, but there is an immediate workaround you can use until then. You can put this in user.config

<add key="aspnet:MaxHttpCollectionKeys" value="1500"/>

you may need to experiment with the number depending on how many roles you have, maybe try 2000, and then reduce it as low as possible until the error returns and then put it a little higher so the error does not happen.

You might also review your roles and if you have some that are no longer used remove them.

Best,

Joe

1/5/2012 9:34:49 AM
Gravatar
Total Posts 149
Partner
mojoPortal Skinning, Custom Development and Support in Italy?
EffectiveWeb.it

Re: Server Error in '/' Application while Saving Site Settings

Thanks!!!

It works just with 1500.

That also explains the erraic error we got from another custom module.

I will use the suggested workaround when needed until the new release is available.

Best Regards!

Diego

1/5/2012 9:39:25 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

Hi Diego,

I would still reduce it as much as possible, the default is 1000 so it will have to be a number higher than that, but if 1100 works I'd use 1100 instead of 1500. 

Best,

Joe

1/11/2012 8:55:31 PM
Gravatar
Total Posts 4

Re: Server Error in '/' Application while Saving Site Settings

Thanks for this... it solved the same issue for me.  I was able to get away with 1100, no problem.

  <add key="aspnet:MaxHttpCollectionKeys" value="1100"/>

Andrew

1/12/2012 8:15:59 AM
Gravatar
Total Posts 3

Re: Server Error in '/' Application while Saving Site Settings

I got the same error on Modulesetting.aspx page when I tried to Save my settings.

I also added

<add key="aspnet:MaxHttpCollectionKeys" value="2100"/>

as per guidence, but it wont work.

 operating system: windows 2008 R2 MSSQL

 

Looking for help.

 

Thanks in advance

1/12/2012 11:55:26 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

Hi,

Is it a custom feature?

How many settings does the feature have?

How many roles do you have?

I think you will have to increase the number until the error stops happening. 

Hope that helps,

Joe

1/12/2012 5:38:19 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Server Error in '/' Application while Saving Site Settings

Hi Joe, unfortunately we just came across another area of the system that is impacted big time by this ASP.NET update: The Content Manager publishing page. My webmaster brought me this same error--she was getting it when trying to publish a content instance to a page (error happens as soon as she hits the green + icon).

I was able to get Publish to work for our site by setting aspnet:MaxHttpCollectionKeys to 3000 (2,500 still didn't work).

For reference, we have 942 items in mp_pagemodules for the site. It seems that to work around the issue with this page, aspnet:MaxHttpCollectionKeys needs to be set to higher than three times the number of pagemodules for a site, so any site with more than 333 modules would be affected.

Thanks,
Jamie

1/13/2012 7:43:49 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

Hi Jamie,

Thanks for letting me know, I'll look into a fix for this. However, I think it is based on the total number of pages not pagemodules because on that page one module is represented and the rows are per page, pagemodules only represent the rows that are published.

Best,

Joe

1/17/2012 9:41:41 AM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Server Error in '/' Application while Saving Site Settings

Thanks Joe. If it helps your testing, we have 777 pages in the affected site right now.

Jamie

1/17/2012 9:56:11 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

Hi Jamie,

After looking into it I realized it doesn't correspond exactly to the number of items because its the hidden viewstate fields (required to support grid events) that start to add up in addition to the actual form elements needed for each row such as the image button per page row. The number of viewstate fields can be affected by configuration on the <pages maxPageStateFieldLength="100" 

We use a small size (100) mainly because some mobile browsers will ignore hidden fields if they are very large, but we probably could go higher than 100 if needed to reduce the number of hidden fields.

I've got a solution for it already in my branch in the repository that should be in the default branch in the next day or so. Basically if the number of pages is higher than a config setting (default is 150) it will change the functionality such that when you click the button it opens a dialog page instead of going into edit mode of the grid. That way there is no change for small sites.

Best,

Joe

1/17/2012 4:25:57 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Server Error in '/' Application while Saving Site Settings

That sounds great Joe, thanks. I'm glad you didn't have to rejigger that interface completely. I've always liked the way it works.

Jamie

8/6/2012 3:18:35 AM
Gravatar
Total Posts 1

Re: Server Error in '/' Application while Saving Site Settings

Hi team,

i tried with your solution but it does't work.

 

The Error i got is below:- 

 

 

[Server Error in '/Dinesh_Export/Admin' Application.

Operation is not valid due to the current state of the object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +128
System.Web.HttpRequest.FillInFormCollection() +154

[HttpException (0x80004005): The URL-encoded form data is not valid.]
System.Web.HttpRequest.FillInFormCollection() +213
System.Web.HttpRequest.get_Form() +50
System.Web.TraceContext.InitRequest()
System.Web.TraceContext.VerifyStart()
System.Web.Util.Profiler.StartRequest(HttpContext context)
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +486

Version Information: Microsoft .NET Framework Version:1.1.4322.2494; ASP.NET Version:1.1.4322.2494

 

My problem is on the application, we have 1071 check boxes for selecting the countries(Row wise) with the ICON TERMS(column wise). we have 7 icon terms and if we select complete column more than 5 and click on save then we are getting this error and if we select Complete column below 5 we are able to save them with out any error.

I am copying my code as well below :-

 

UserEdit.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace XPortAdmin
{
/// <summary>
/// Summary description for UserEdit.
/// </summary>
public class UserEdit : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUserId;
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtUserEmail;
protected System.Web.UI.WebControls.CheckBox chkActive;
protected System.Web.UI.WebControls.Label lblHeader;
protected System.Web.UI.HtmlControls.HtmlGenericControl divCountries;
protected System.Web.UI.HtmlControls.HtmlInputHidden hidPB_Reason;
protected System.Web.UI.HtmlControls.HtmlInputHidden hidFocusOn;
protected System.Web.UI.WebControls.DataGrid dgRoles;
protected System.Web.UI.HtmlControls.HtmlGenericControl divRoles;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ct3_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctE_set;

//BEGIN CR KFCQ00123223
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctNAI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctEUI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctNAUS_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctLAI_set;
//END CR KFCQ00123223

protected System.Web.UI.WebControls.DataGrid dgCountries;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{

dgCountries.DataSource = Common.getCountriesSortedByName();
dgCountries.DataBind();

dgRoles.DataSource = Common.dvRoles;
dgRoles.DataBind();

if (Request["uid"] != null)
{
showExistingUser(Request["uid"].ToString());
if (Request["copy"] != null)
{
txtUserId.BackColor = Color.White;
txtUserId.Text = "";
txtUserName.Text = "";
txtUserEmail.Text = "";
txtUserId.ReadOnly = false;
}
}
else
{
txtUserId.BackColor = Color.White;
hidFocusOn.Value = "txtUserId";
}

return;
}

if (hidPB_Reason.Value == "save")
verify_and_save();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgCountries.SelectedIndexChanged += new System.EventHandler(this.dgCountries_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void verify_and_save()
{
string countries = ComposeCountryString();
string role = "";

if (txtUserId.Text.Trim().Length == 0)
{
showAlert("User Logon ID must be entered", "txtUserId");
return;
}
if (txtUserName.Text.Trim().Length == 0)
{
showAlert("User Name must be entered", "txtUserName");
return;
}
if (txtUserEmail.Text.Trim().Length == 0)
{
showAlert("Email Address must be entered", "txtUserEmail");
return;
}

foreach (DataGridItem dgi in dgRoles.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
HtmlInputRadioButton rb = (HtmlInputRadioButton)(dgi.Cells[2].Controls[1]);
if (rb.Checked)
{
role = dgi.Cells[0].Text;
}
}
}
if (role.Length == 0)
{
showAlert("Select a Role", "");
return;
}

if (Request["uid"] != null)
if (Request["copy"] == null)
{
Common.ExecNonQuery(makeUpdateUser(countries, role));
}
else
{
Common.ExecNonQuery(makeInsertUser(countries, role));
}
else
Common.ExecNonQuery(makeInsertUser(countries, role));

string s = "window.opener.document.getElementById('hidRefreshUserPage').value = 'y';";
s += "window.close();";
s += "<script>" + s + "</script>";
Page.RegisterClientScriptBlock("gettingout",s);

Common.setDataReloadSignal();

}

private string ComposeCountryString()
{
string countries = String.Empty;

bool bAllCountries = true;
foreach (DataGridItem dgi in dgCountries.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
HtmlInputCheckBox rb_inter = (HtmlInputCheckBox)(dgi.Cells[2].Controls[1]);
HtmlInputCheckBox rb_3rd = (HtmlInputCheckBox)(dgi.Cells[3].Controls[1]);
HtmlInputCheckBox rb_kic = (HtmlInputCheckBox)(dgi.Cells[4].Controls[1]);
//BEGIN CR KFCQ00123223
HtmlInputCheckBox rb_nai = (HtmlInputCheckBox)(dgi.Cells[5].Controls[1]);
HtmlInputCheckBox rb_eui = (HtmlInputCheckBox)(dgi.Cells[6].Controls[1]);
HtmlInputCheckBox rb_naus = (HtmlInputCheckBox)(dgi.Cells[7].Controls[1]);
HtmlInputCheckBox rb_lai = (HtmlInputCheckBox)(dgi.Cells[8].Controls[1]);
//END CR KFCQ00123223
int k = 0;
if (rb_inter.Checked) k += 1;
if (rb_3rd.Checked) k += 2;
if (rb_kic.Checked) k += 4;
//BEGIN CR KFCQ00123223
if(rb_nai.Checked) k+=8;
if(rb_eui.Checked) k+=16;
if(rb_naus.Checked) k+=32;
if(rb_lai.Checked)k+=64;
//END CR KFCQ00123223
//BEGIN modified for CR KFCQ00123223
//if (k < 7)
if(k<127)
bAllCountries = false;
if (k > 0)
countries += dgi.Cells[0].Text + k.ToString() + "|";
//END CR KFCQ00123223
}
}
if (countries.Length > 0)
countries = countries.Substring(0,countries.Length - 1);
if (bAllCountries)
countries = "ALL";

return countries;
}

private void showAlert(string msg, string foc)
{
Page.RegisterStartupScript("inputerr","<script>alert('" + msg + "');</script>");
if (foc.Length > 0) hidFocusOn.Value=foc;
}

private string makeInsertUser(string countries, string role)
{
string sF = "Insert into " + Common.tblUser + " (";
string sV = " values (";

Common.addFieldForInsert(ref sF, ref sV, "NTUserId", txtUserId.Text.Trim(), true);
Common.addFieldForInsert(ref sF, ref sV, "UserName", txtUserName.Text.Trim(), true);
Common.addFieldForInsert(ref sF, ref sV, "UserCountries", countries, true);
Common.addFieldForInsert(ref sF, ref sV, "UserRole", role, true);
Common.addFieldForInsert(ref sF, ref sV, "UserActive", (chkActive.Checked)?"1":"0", false);
Common.addFieldForInsert(ref sF, ref sV, "UserEmail", txtUserEmail.Text.Trim(), true);

sF += ")";
sV += ")";

return sF + sV;
}

private string makeUpdateUser(string countries, string role)
{
string sSql = "";
sSql = "Update " + Common.tblUser + " set ";
sSql += Common.setFieldForUpdt("UserName", txtUserName.Text.Trim(), true);
sSql += ", " + Common.setFieldForUpdt("UserCountries",countries, true);
sSql += ", " + Common.setFieldForUpdt("UserRole",role, true);
sSql += ", " + Common.setFieldForUpdt("UserActive",(chkActive.Checked)?"1":"0", false);
sSql += ", " + Common.setFieldForUpdt("UserEmail",txtUserEmail.Text.Trim(), true);

sSql += " where NTUserId='" + txtUserId.Text.Trim() + "'";

return sSql;
}

private void showExistingUser(string uid)
{
txtUserId.ReadOnly = true;

DataTable dt = Common.getUser(uid);
txtUserId.Text = dt.Rows[0]["NTUserId"].ToString();
txtUserName.Text = dt.Rows[0]["UserName"].ToString();
txtUserEmail.Text = dt.Rows[0]["UserEmail"].ToString();
chkActive.Checked = dt.Rows[0]["UserActive"].ToString() != "0";

string sCountries = dt.Rows[0]["UserCountries"].ToString();

int cti_count = 0, ct3_count = 0, cte_count = 0;

//BEGIN CR KFCQ00123223
int ctnai_count=0,ctnaus_count=0,cteui_count=0,ctlai_count=0;
//END CR KFCQ00123223

foreach (DataGridItem dgi in dgCountries.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
// see if the country code for this grid row (2 chars) is amoung
// the pipe-separted list of country codes (+ digit appended) of this NT User:
int k = sCountries.IndexOf(dgi.Cells[0].Text);
if (sCountries == "ALL" || k != -1)
{
HtmlInputCheckBox rb_inter = (HtmlInputCheckBox)(dgi.Cells[2].Controls[1]);
HtmlInputCheckBox rb_3rd = (HtmlInputCheckBox)(dgi.Cells[3].Controls[1]);
HtmlInputCheckBox rb_kic = (HtmlInputCheckBox)(dgi.Cells[4].Controls[1]);
//BEGIN CR KFCQ00123223
HtmlInputCheckBox rb_nai = (HtmlInputCheckBox)(dgi.Cells[5].Controls[1]);
HtmlInputCheckBox rb_eui = (HtmlInputCheckBox)(dgi.Cells[6].Controls[1]);
HtmlInputCheckBox rb_naus = (HtmlInputCheckBox)(dgi.Cells[7].Controls[1]);
HtmlInputCheckBox rb_lai = (HtmlInputCheckBox)(dgi.Cells[8].Controls[1]);
//END CR KFCQ00123223

if (sCountries == "ALL")
{
rb_inter.Checked = true;
rb_3rd.Checked = true;
rb_kic.Checked = true;

//BEGIN CR KFCQ00123223
rb_eui.Checked = true;
rb_nai.Checked = true;
rb_naus.Checked = true;
rb_lai.Checked = true;
//END CR KFCQ00123223
}
else
{
k += 2; // step beyond 2-char code
if (k > sCountries.Length - 1 || sCountries.Substring(k,1) == "|")
{
// we are beyond the string or bumped into pipe (no digit after code - assume all cust types)
rb_inter.Checked = true;
rb_3rd.Checked = true;
rb_kic.Checked = true;

//BEGIN CR KFCQ00123223
rb_nai.Checked = true;
rb_eui.Checked = true;
rb_naus.Checked = true;
rb_lai.Checked = true;
//END CR KFCQ00123223
}
else
{
//BEGIN CR KFCQ00123223
//bug fix - (KFCQ00123223) email notification bug-C0000019015

string[] arCountries;
arCountries = sCountries.Split(new char[] {'|'});
for (int i=0; i < arCountries.Length; i=i+1)
{
if(arCountries[i].Substring(0,2)== dgi.Cells[0].Text)
{
int w = Convert.ToInt32(arCountries[i].Substring(2));

//int j=0;
//int charCount=1;
//int navCountry=k;
//while (j!=-1)
//{
// char c=sCountries.Substring(navCountry,1).ToCharArray()[0];
// if(c=='|' || navCountry==sCountries.Length-1)
// {
// j=-1;
// if (charCount==1)
// {
// charCount+=1;
// }
//
// }
// else
// {
// if(navCountry<sCountries.Length-1)
// {
// navCountry+=1;
// }
// else
// {
// navCountry=sCountries.Length-1;
// }
// charCount+=1;
// }
// }
// //sxl:qf; next 2 lines temp fix for 3-letter codes !
// char char3 = sCountries.Substring(k,1).ToCharArray()[0];
// if (char3 < '0' || char3 > '9') k++;
// // assume one digit only after country code:
// string s=sCountries.Substring(k,charCount-1);
// int w = Convert.ToInt32(sCountries.Substring(k,charCount-1));
if ((w & 0x01) > 0) rb_inter.Checked = true;
if ((w & 0x02) > 0) rb_3rd.Checked = true;
if ((w & 0x04) > 0) rb_kic.Checked = true;
if ((w & 0x08) > 0) rb_nai.Checked = true;
if ((w & 0x10) > 0) rb_eui.Checked = true;
if ((w & 0x20) > 0) rb_naus.Checked = true;
if ((w & 0x40) > 0) rb_lai.Checked = true;
//this below break is added to increase the effeciency of the code
//C0000019015
break;
}
}

//END CR KFCQ00123223
////// //sxl:qf; next 2 lines temp fix for 3-letter codes !
////// char char3 = sCountries.Substring(k,1).ToCharArray()[0];
////// if (char3 < '0' || char3 > '9') k++;
////// // assume one digit only after country code:
////// int w = Convert.ToInt32(sCountries.Substring(k,1));
////// if ((w & 0x01) > 0) rb_inter.Checked = true;
////// if ((w & 0x02) > 0) rb_3rd.Checked = true;
////// if ((w & 0x04) > 0) rb_kic.Checked = true;
//////
}
}
if (rb_inter.Checked) cti_count++;
if (rb_3rd.Checked) ct3_count++;
if (rb_kic.Checked) cte_count++;

//BEGIN CR KFCQ00123223
if (rb_nai.Checked) ctnai_count++;
if (rb_eui.Checked) cteui_count++;
if (rb_naus.Checked) ctnaus_count++;
if (rb_lai.Checked) ctlai_count++;
//END CR KFCQ00123223
}
}
}

if (dgCountries.Items.Count == cti_count) hid_ctI_set.Value = "y";
if (dgCountries.Items.Count == ct3_count) hid_ct3_set.Value = "y";
if (dgCountries.Items.Count == cte_count) hid_ctE_set.Value = "y";

//BEGIN CR KFCQ00123223
if (dgCountries.Items.Count == ctnai_count) hid_ctNAI_set.Value = "y";
if (dgCountries.Items.Count == cteui_count) hid_ctEUI_set.Value = "y";
if (dgCountries.Items.Count == ctnaus_count) hid_ctNAUS_set.Value = "y";
if (dgCountries.Items.Count == ctlai_count) hid_ctLAI_set.Value = "y";
//END CR KFCQ00123223

foreach (DataGridItem dgi in dgRoles.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
if (dt.Rows[0]["UserRole"].ToString().IndexOf(dgi.Cells[0].Text) != -1)
{
System.Web.UI.HtmlControls.HtmlInputRadioButton rb =
(System.Web.UI.HtmlControls.HtmlInputRadioButton)(dgi.Cells[2].Controls[1]);
rb.Checked = true;
}
}
}
}

private void dgCountries_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

}
}

UserEdit.aspx

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace XPortAdmin
{
/// <summary>
/// Summary description for UserEdit.
/// </summary>
public class UserEdit : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUserId;
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtUserEmail;
protected System.Web.UI.WebControls.CheckBox chkActive;
protected System.Web.UI.WebControls.Label lblHeader;
protected System.Web.UI.HtmlControls.HtmlGenericControl divCountries;
protected System.Web.UI.HtmlControls.HtmlInputHidden hidPB_Reason;
protected System.Web.UI.HtmlControls.HtmlInputHidden hidFocusOn;
protected System.Web.UI.WebControls.DataGrid dgRoles;
protected System.Web.UI.HtmlControls.HtmlGenericControl divRoles;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ct3_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctE_set;

//BEGIN CR KFCQ00123223
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctNAI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctEUI_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctNAUS_set;
protected System.Web.UI.HtmlControls.HtmlInputHidden hid_ctLAI_set;
//END CR KFCQ00123223

protected System.Web.UI.WebControls.DataGrid dgCountries;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{

dgCountries.DataSource = Common.getCountriesSortedByName();
dgCountries.DataBind();

dgRoles.DataSource = Common.dvRoles;
dgRoles.DataBind();

if (Request["uid"] != null)
{
showExistingUser(Request["uid"].ToString());
if (Request["copy"] != null)
{
txtUserId.BackColor = Color.White;
txtUserId.Text = "";
txtUserName.Text = "";
txtUserEmail.Text = "";
txtUserId.ReadOnly = false;
}
}
else
{
txtUserId.BackColor = Color.White;
hidFocusOn.Value = "txtUserId";
}

return;
}

if (hidPB_Reason.Value == "save")
verify_and_save();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgCountries.SelectedIndexChanged += new System.EventHandler(this.dgCountries_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void verify_and_save()
{
string countries = ComposeCountryString();
string role = "";

if (txtUserId.Text.Trim().Length == 0)
{
showAlert("User Logon ID must be entered", "txtUserId");
return;
}
if (txtUserName.Text.Trim().Length == 0)
{
showAlert("User Name must be entered", "txtUserName");
return;
}
if (txtUserEmail.Text.Trim().Length == 0)
{
showAlert("Email Address must be entered", "txtUserEmail");
return;
}

foreach (DataGridItem dgi in dgRoles.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
HtmlInputRadioButton rb = (HtmlInputRadioButton)(dgi.Cells[2].Controls[1]);
if (rb.Checked)
{
role = dgi.Cells[0].Text;
}
}
}
if (role.Length == 0)
{
showAlert("Select a Role", "");
return;
}

if (Request["uid"] != null)
if (Request["copy"] == null)
{
Common.ExecNonQuery(makeUpdateUser(countries, role));
}
else
{
Common.ExecNonQuery(makeInsertUser(countries, role));
}
else
Common.ExecNonQuery(makeInsertUser(countries, role));

string s = "window.opener.document.getElementById('hidRefreshUserPage').value = 'y';";
s += "window.close();";
s += "<script>" + s + "</script>";
Page.RegisterClientScriptBlock("gettingout",s);

Common.setDataReloadSignal();

}

private string ComposeCountryString()
{
string countries = String.Empty;

bool bAllCountries = true;
foreach (DataGridItem dgi in dgCountries.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
HtmlInputCheckBox rb_inter = (HtmlInputCheckBox)(dgi.Cells[2].Controls[1]);
HtmlInputCheckBox rb_3rd = (HtmlInputCheckBox)(dgi.Cells[3].Controls[1]);
HtmlInputCheckBox rb_kic = (HtmlInputCheckBox)(dgi.Cells[4].Controls[1]);
//BEGIN CR KFCQ00123223
HtmlInputCheckBox rb_nai = (HtmlInputCheckBox)(dgi.Cells[5].Controls[1]);
HtmlInputCheckBox rb_eui = (HtmlInputCheckBox)(dgi.Cells[6].Controls[1]);
HtmlInputCheckBox rb_naus = (HtmlInputCheckBox)(dgi.Cells[7].Controls[1]);
HtmlInputCheckBox rb_lai = (HtmlInputCheckBox)(dgi.Cells[8].Controls[1]);
//END CR KFCQ00123223
int k = 0;
if (rb_inter.Checked) k += 1;
if (rb_3rd.Checked) k += 2;
if (rb_kic.Checked) k += 4;
//BEGIN CR KFCQ00123223
if(rb_nai.Checked) k+=8;
if(rb_eui.Checked) k+=16;
if(rb_naus.Checked) k+=32;
if(rb_lai.Checked)k+=64;
//END CR KFCQ00123223
//BEGIN modified for CR KFCQ00123223
//if (k < 7)
if(k<127)
bAllCountries = false;
if (k > 0)
countries += dgi.Cells[0].Text + k.ToString() + "|";
//END CR KFCQ00123223
}
}
if (countries.Length > 0)
countries = countries.Substring(0,countries.Length - 1);
if (bAllCountries)
countries = "ALL";

return countries;
}

private void showAlert(string msg, string foc)
{
Page.RegisterStartupScript("inputerr","<script>alert('" + msg + "');</script>");
if (foc.Length > 0) hidFocusOn.Value=foc;
}

private string makeInsertUser(string countries, string role)
{
string sF = "Insert into " + Common.tblUser + " (";
string sV = " values (";

Common.addFieldForInsert(ref sF, ref sV, "NTUserId", txtUserId.Text.Trim(), true);
Common.addFieldForInsert(ref sF, ref sV, "UserName", txtUserName.Text.Trim(), true);
Common.addFieldForInsert(ref sF, ref sV, "UserCountries", countries, true);
Common.addFieldForInsert(ref sF, ref sV, "UserRole", role, true);
Common.addFieldForInsert(ref sF, ref sV, "UserActive", (chkActive.Checked)?"1":"0", false);
Common.addFieldForInsert(ref sF, ref sV, "UserEmail", txtUserEmail.Text.Trim(), true);

sF += ")";
sV += ")";

return sF + sV;
}

private string makeUpdateUser(string countries, string role)
{
string sSql = "";
sSql = "Update " + Common.tblUser + " set ";
sSql += Common.setFieldForUpdt("UserName", txtUserName.Text.Trim(), true);
sSql += ", " + Common.setFieldForUpdt("UserCountries",countries, true);
sSql += ", " + Common.setFieldForUpdt("UserRole",role, true);
sSql += ", " + Common.setFieldForUpdt("UserActive",(chkActive.Checked)?"1":"0", false);
sSql += ", " + Common.setFieldForUpdt("UserEmail",txtUserEmail.Text.Trim(), true);

sSql += " where NTUserId='" + txtUserId.Text.Trim() + "'";

return sSql;
}

private void showExistingUser(string uid)
{
txtUserId.ReadOnly = true;

DataTable dt = Common.getUser(uid);
txtUserId.Text = dt.Rows[0]["NTUserId"].ToString();
txtUserName.Text = dt.Rows[0]["UserName"].ToString();
txtUserEmail.Text = dt.Rows[0]["UserEmail"].ToString();
chkActive.Checked = dt.Rows[0]["UserActive"].ToString() != "0";

string sCountries = dt.Rows[0]["UserCountries"].ToString();

int cti_count = 0, ct3_count = 0, cte_count = 0;

//BEGIN CR KFCQ00123223
int ctnai_count=0,ctnaus_count=0,cteui_count=0,ctlai_count=0;
//END CR KFCQ00123223

foreach (DataGridItem dgi in dgCountries.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
// see if the country code for this grid row (2 chars) is amoung
// the pipe-separted list of country codes (+ digit appended) of this NT User:
int k = sCountries.IndexOf(dgi.Cells[0].Text);
if (sCountries == "ALL" || k != -1)
{
HtmlInputCheckBox rb_inter = (HtmlInputCheckBox)(dgi.Cells[2].Controls[1]);
HtmlInputCheckBox rb_3rd = (HtmlInputCheckBox)(dgi.Cells[3].Controls[1]);
HtmlInputCheckBox rb_kic = (HtmlInputCheckBox)(dgi.Cells[4].Controls[1]);
//BEGIN CR KFCQ00123223
HtmlInputCheckBox rb_nai = (HtmlInputCheckBox)(dgi.Cells[5].Controls[1]);
HtmlInputCheckBox rb_eui = (HtmlInputCheckBox)(dgi.Cells[6].Controls[1]);
HtmlInputCheckBox rb_naus = (HtmlInputCheckBox)(dgi.Cells[7].Controls[1]);
HtmlInputCheckBox rb_lai = (HtmlInputCheckBox)(dgi.Cells[8].Controls[1]);
//END CR KFCQ00123223

if (sCountries == "ALL")
{
rb_inter.Checked = true;
rb_3rd.Checked = true;
rb_kic.Checked = true;

//BEGIN CR KFCQ00123223
rb_eui.Checked = true;
rb_nai.Checked = true;
rb_naus.Checked = true;
rb_lai.Checked = true;
//END CR KFCQ00123223
}
else
{
k += 2; // step beyond 2-char code
if (k > sCountries.Length - 1 || sCountries.Substring(k,1) == "|")
{
// we are beyond the string or bumped into pipe (no digit after code - assume all cust types)
rb_inter.Checked = true;
rb_3rd.Checked = true;
rb_kic.Checked = true;

//BEGIN CR KFCQ00123223
rb_nai.Checked = true;
rb_eui.Checked = true;
rb_naus.Checked = true;
rb_lai.Checked = true;
//END CR KFCQ00123223
}
else
{
//BEGIN CR KFCQ00123223
//bug fix - (KFCQ00123223) email notification bug-C0000019015

string[] arCountries;
arCountries = sCountries.Split(new char[] {'|'});
for (int i=0; i < arCountries.Length; i=i+1)
{
if(arCountries[i].Substring(0,2)== dgi.Cells[0].Text)
{
int w = Convert.ToInt32(arCountries[i].Substring(2));

//int j=0;
//int charCount=1;
//int navCountry=k;
//while (j!=-1)
//{
// char c=sCountries.Substring(navCountry,1).ToCharArray()[0];
// if(c=='|' || navCountry==sCountries.Length-1)
// {
// j=-1;
// if (charCount==1)
// {
// charCount+=1;
// }
//
// }
// else
// {
// if(navCountry<sCountries.Length-1)
// {
// navCountry+=1;
// }
// else
// {
// navCountry=sCountries.Length-1;
// }
// charCount+=1;
// }
// }
// //sxl:qf; next 2 lines temp fix for 3-letter codes !
// char char3 = sCountries.Substring(k,1).ToCharArray()[0];
// if (char3 < '0' || char3 > '9') k++;
// // assume one digit only after country code:
// string s=sCountries.Substring(k,charCount-1);
// int w = Convert.ToInt32(sCountries.Substring(k,charCount-1));
if ((w & 0x01) > 0) rb_inter.Checked = true;
if ((w & 0x02) > 0) rb_3rd.Checked = true;
if ((w & 0x04) > 0) rb_kic.Checked = true;
if ((w & 0x08) > 0) rb_nai.Checked = true;
if ((w & 0x10) > 0) rb_eui.Checked = true;
if ((w & 0x20) > 0) rb_naus.Checked = true;
if ((w & 0x40) > 0) rb_lai.Checked = true;
//this below break is added to increase the effeciency of the code
//C0000019015
break;
}
}

//END CR KFCQ00123223
////// //sxl:qf; next 2 lines temp fix for 3-letter codes !
////// char char3 = sCountries.Substring(k,1).ToCharArray()[0];
////// if (char3 < '0' || char3 > '9') k++;
////// // assume one digit only after country code:
////// int w = Convert.ToInt32(sCountries.Substring(k,1));
////// if ((w & 0x01) > 0) rb_inter.Checked = true;
////// if ((w & 0x02) > 0) rb_3rd.Checked = true;
////// if ((w & 0x04) > 0) rb_kic.Checked = true;
//////
}
}
if (rb_inter.Checked) cti_count++;
if (rb_3rd.Checked) ct3_count++;
if (rb_kic.Checked) cte_count++;

//BEGIN CR KFCQ00123223
if (rb_nai.Checked) ctnai_count++;
if (rb_eui.Checked) cteui_count++;
if (rb_naus.Checked) ctnaus_count++;
if (rb_lai.Checked) ctlai_count++;
//END CR KFCQ00123223
}
}
}

if (dgCountries.Items.Count == cti_count) hid_ctI_set.Value = "y";
if (dgCountries.Items.Count == ct3_count) hid_ct3_set.Value = "y";
if (dgCountries.Items.Count == cte_count) hid_ctE_set.Value = "y";

//BEGIN CR KFCQ00123223
if (dgCountries.Items.Count == ctnai_count) hid_ctNAI_set.Value = "y";
if (dgCountries.Items.Count == cteui_count) hid_ctEUI_set.Value = "y";
if (dgCountries.Items.Count == ctnaus_count) hid_ctNAUS_set.Value = "y";
if (dgCountries.Items.Count == ctlai_count) hid_ctLAI_set.Value = "y";
//END CR KFCQ00123223

foreach (DataGridItem dgi in dgRoles.Items)
{
if (dgi.ItemType == ListItemType.Item || dgi.ItemType == ListItemType.AlternatingItem)
{
if (dt.Rows[0]["UserRole"].ToString().IndexOf(dgi.Cells[0].Text) != -1)
{
System.Web.UI.HtmlControls.HtmlInputRadioButton rb =
(System.Web.UI.HtmlControls.HtmlInputRadioButton)(dgi.Cells[2].Controls[1]);
rb.Checked = true;
}
}
}
}

private void dgCountries_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

}
}

 

Can anyone help me on this. i am struggling with this from last 4 days...

 

Regards,

Jack147

 

8/6/2012 6:31:13 AM
Gravatar
Total Posts 18439

Re: Server Error in '/' Application while Saving Site Settings

You just have to set this value higher and higher until the error goes away in user.config or web.config. If you put it in user.config you need to touch web.config because changes in user.config are not automatically detected.

<add key="aspnet:MaxHttpCollectionKeys" value="2100"/>

its the number of input elements including the viewstate adds up to a high number so you may need to bump that number way up.

Aside from that, your code looks to me like it is vulnerable to sql injection attacks because you are not using parmaterized queries you are concatenating user input into a sql string which is dangerous. Maybe your function Common.addFieldForInsert(...) does some sanitization but I would use parameters to make sure.

You must sign in to post in the forums. This thread is closed to new posts.