0

I am working on cas authentication. I am trying to take USER name after verifying user then creating xml file of different roles of user name. this xml file will be used later on. Here I am trying to create XML file which is displaying problem.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Xml;
using System.Data.SqlClient;
using System.Data;



namespace WebApplication3
{
   public partial class WebForm1 : System.Web.UI.Page
   {
    public WebForm1()
    {
        //InitializeComponent();

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();



        Response.ContentType = "text/xml";
        Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
        Response.Write("<?xml-stylesheet type=\"text/xsl\" ?>\r\n");

        Response.Write("<Users>\r\n");

        String UserName = "USERname";
        DirectoryEntry de = new DirectoryEntry("ldap://URL", "USERname", "PAssword");

        // object obj = de.NativeObject;
        DirectorySearcher searcher = new DirectorySearcher(de);
        searcher.Filter = "(&(ObjectClass=user)(sAMAccountName=" + UserName + "))";

        searcher.PropertiesToLoad.Add("memberOf");
        StringBuilder groupNames = new StringBuilder(); //stuff them in | delimited

        try
        {

            SearchResult result = searcher.FindOne();

            int propertyCount = result.Properties["memberOf"].Count;
            string dn;
            int equalsIndex, commaIndex;

            for (int propertyCounter = 0; propertyCounter < propertyCount;
                propertyCounter++)
            {
                dn = (string)result.Properties["memberOf"][propertyCounter];
                equalsIndex = dn.IndexOf("=", 1);
                commaIndex = dn.IndexOf(",", 1);
                if (-1 == equalsIndex)
                {
                    Response.Write(null);
                }



                 Response.Write("<User>\r\n");
                 Response.Write("<UserName>" + UserName + "</UserName>\r\n");
                 Response.Write("<Roles>" + groupNames.ToString() + "</Roles>\r\n");

                  Response.Write("</User>\r\n");

            }
              Response.Write("<Users>\r\n");

        }


        catch (Exception ex)
        {
            throw new Exception("Error obtaining group names. " + ex.Message);
        }

        // Response.Write(groupNames.ToString()); 
       }
    }
}
Unknown
  • 25
  • 6
  • Possible duplicate of [Error 0x80005000 and DirectoryServices](http://stackoverflow.com/questions/1722398/error-0x80005000-and-directoryservices) – cbr Dec 09 '15 at 18:48
  • Do you have a problem with your code? Side note: please use XML apis (XDocument for example) to generate XML... – Alexei Levenkov Dec 09 '15 at 19:00
  • I unable to figure it out what is the exact problem. It showing some error at run time. like exception error. I checked other similar question. but it did not worked – Unknown Dec 09 '15 at 19:06
  • {System.Exception: Error obtaining group names. Unknown error (0x80005000) at WebApplication3.WebForm1.Page_Load(Object sender, EventArgs e) in Default.aspx.cs:line 91 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)} – Unknown Dec 09 '15 at 19:08
  • You are missing the forward slash in the closing tag : Response.Write("\r\n"); Should be Response.Write("\r\n"); – jdweng Dec 09 '15 at 20:31

0 Answers0