Asp.net Web应用程序未显示在客户端工作站上

时间:2011-06-23 15:05:47

标签: asp.net visual-studio-2010 iis sharepoint-2010

我已经开始提出这个问题,但我想我可能需要改写它。我有一个我在VS2010中构建的asp.net Web应用程序,它发布到我们的Sharepoint站点。该站点基本上是一个用于执行员工状态更改请求的表单,我需要它来填充活动目录查询中的下拉框。我已经设置了这一切并且在我们的服务器上工作得非常好......但是当我去工作站上访问该站点时,我得到一个实例错误并抛出一个空引用。看起来它告诉我它没有运行活动目录查询方法。

这是错误:

    Server Error in '/Requests' Application.

Object reference not set to an instance of an 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.NullReferenceException: Object reference not set to an instance of an 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: 


[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +562
   System.Web.UI.WebControls.ListControl.PerformSelect() +48
   RequestForm._Default.Page_Load(Object sender, EventArgs e) +1464
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +41
   System.Web.UI.Control.OnLoad(EventArgs e) +131
   System.Web.UI.Control.LoadRecursive() +65
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427

这是基本基本上只加载列表的adquery:

 public PreLoadForm()
        {
            //empty constructor calls the search method when class is instantiated
            ADSearch();
            //and sorts the array
            SortList(groups);
        }


        public string[] Groups //property to pass the groups array over to the calling class
        {
            get
            {
                return groups;
            }
        }


        protected void ADSearch()
        {
            //The Active Directory Search

            int x; //index variable for loading array

            domainName = "******"; //the domain

            theQuery = "(&(objectClass=group)(description=branch*))"; //the query statement

            groups = new string[14]; //instantiating the groups array

            #region
            theEntry = new DirectoryEntry("LDAP://DC=" + domainName + ", DC=***", "*******", "*********"); //LDAP entry
            #endregion
            theSearch = new DirectorySearcher(theEntry); //new search of the directory using the entry to connect

            theSearch.Filter = theQuery; //use our query statement for a search filter

            theSearch.PropertiesToLoad.Add("name"); //the value we want back from the search

            try
            {
                //assign the the search findings to a results collection
                mySearchResultColl = theSearch.FindAll();
            }
            catch
            {

            }


            x = 0;

            try
            {
                //loop through the search results
                foreach (SearchResult sr in mySearchResultColl)
                {
                    DirectoryEntry de = sr.GetDirectoryEntry(); //assign the search entries to a directory entry
                    groups[x] = de.Properties["name"].Value.ToString(); //assign the desired value to the array
                    x++; //increment the index

                }
            }
            catch
            {

            }
        }

页面加载:

 protected void Page_Load(object sender, EventArgs e)
        {
            //when the form loads, instantiate the preLoadForm
            LoadForm = new PreLoadForm();

            unselectedArray = new string[numOfOffices]; //instantiate the unselected array

            unselectedArray = LoadForm.Groups; //and load the array from Active Directory

            if (!Page.IsPostBack) //if page has not be reloaded
            {
                //disable certain entries until selected
                officesDropDownList.Enabled = false;
                equipDropDownList.Enabled = false;
                positionTextBox.Enabled = false;
                managerTextBox.Enabled = false;
                terminationTextBox.Enabled = false;
                pcCheckBox.Enabled = false;
                laptopCheckBox.Enabled = false;


                for (int x = 0; x < numOfOffices; x++) //loop the number of times we have offices
                {
                    removeListBox.Items.Add(unselectedArray[x]); //populate the remove list box with the unselected arrarry
                }

                for (int i = 0; i < LoadForm.EmailGroups.Count; i++) //similar loop for populating email list box
                {
                    removeEmailListBox.Items.Add(LoadForm.EmailGroups.ElementAt<string>(i)); //populate from a list
                    //due to the unkown size nature of the email groups
                }

                try
                {
                    officesDropDownList.DataSource = unselectedArray; //quick and dirty way to load the drop down list with our offices
                    officesDropDownList.DataBind();
                    equipDropDownList.DataSource = unselectedArray; //used to be LoadForm.Groups
                    equipDropDownList.DataBind();
                }
                catch (NullReferenceException exceptEx)
                {
                    string messageString = exceptEx.ToString();
                    Response.Write(@"<script language='javascript'>" + messageString + "</script>");
                }

            }
        }

1 个答案:

答案 0 :(得分:0)

尽我所能在这里关注您的代码。 首先,堆栈跟踪显示调用在第1464行上过去

RequestForm._Default.Page_Load(Object sender, EventArgs e) +1464

我只是假设您为了简洁而省略了其他行,但是在页面加载中添加了很多代码。

这两行是多余的:

unselectedArray = new string[numOfOffices]; //instantiate the unselected array
unselectedArray = LoadForm.Groups; //and load the array from Active Directory

unselectedArray将替换为LoadForm.Groups返回的内容 看起来它会从PreLoadForm.ADSearch()填充,从而为Groups提供一个值。我很好奇你怎么想出14?为什么不使用List<string>

我的建议是没有两块试试......捕捉你吞咽异常的地方。这是不好的做法。找出是否以及为什么会抛出异常。这可能会让你更接近你的问题。