简体   繁体   English

ASP.NET LDAP过滤

[英]ASP.NET LDAP FILTERING

Occasionally, in a search from AD I am getting System.Byte[] responses. 有时,在从AD进行的搜索中,我得到了System.Byte []响应。 If I open the source page file in vs2010 and resave the search returns with no problem. 如果我在vs2010中打开源页面文件并重新保存搜索结果,那将没有问题。

Of Note I am binding the result set to xml. 注意:我将结果集绑定到xml。 I am imagining that this has a-lot to do with it. 我在想这与它有很多关系。

Here is a code-excerpt: 这是一段代码摘录:


    public void bindGridView(string sortExp, string sortOrder)
  {
    DataSet aDataSet = new DataSet();
    XmlDocument xd = LDAPConn(sortExp, sortOrder);
    aDataSet.ReadXml(new StringReader(xd.InnerXml));
    // Bind the DataSet to the grid view
    DataView dv = new DataView();
    string sortMsg = "";
    switch (sortExp)
    {
      case "sn":
        sortMsg = "Lastname";
        break;
      case "department":
        sortMsg = "Department";
        break;
      case "Title":
        sortMsg = "Title";
        break;
      case "physicalDeliveryOfficeName":
        sortMsg = "Store";
        break;
      default:
        sortMsg = sortExp;
        break;
    }
    if (aDataSet.Tables.Count > 0)
    {
      try
      {
        debug(true, "<h2 style='float:right;'><b>Sorting By:</b><strong style='color:#880000;'>" + sortMsg + "</strong> &amp; <b>Direction:</b><strong style='color:#880000;'>" + sortOrder.ToString() + "</strong></h2>");
        dv = aDataSet.Tables[0].DefaultView;
        GridView1.DataSource = dv;
        GridView1.DataBind();
      }
      catch (Exception e)
      {
        debug(true, "<br/><b style='color: rgb(255,0,0);'>Your search returned no results.</b><br/><span style=''>" + e.Message + "<br/>" + e.InnerException + e.Source + "</span>");
      }
    }
  }

I decided to just sanitize the field if string eval = System.Byte[] 我决定只清理string eval = System.Byte[]的字段

public string SanitizeField(SearchResultCollection result, string field)
{
  StringBuilder sb = new StringBuilder();
  foreach (object val in result[0].Properties[field])
  {
    sb.Append("<" + field + ">" + val + "</" + field + ">");
  }
  return sb.ToString();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM