Tuesday, August 23, 2011

Add a new service application pool

 

You can use the New-SPServiceApplicationPool cmdlet to create new Web service application pools in IIS.

PS > New-SPServiceApplicationPool -Name “AppPool” `

>> -account (Get-SPManagedAccount domain\account)

Thursday, March 31, 2011

Get All AD Groups using LDAP in C#

Issue: LDAP Query not pulling all the Active Directory Groups (including subgroups) available in the given domain.

Solution:
To retrieve a set of results that is larger than 1000 items, you must set SizeLimit to its default value (zero) and set PageSize to a value that is less than or equal to 1000.

Concept Source: Click here


public static DataTable GetAllActiveDirectoryGroups(string ldapServer, string ldapUserName, string ldapPassWord)
        {
            DataTable dt = new DataTable();
            DataRow dr;
 
 
            DirectoryEntry de = new DirectoryEntry(ldapServer);
            de.Username = ldapUserName;
            de.Password = ldapPassWord;
            DirectorySearcher deSearch = new DirectorySearcher(de.Path);
            
            SearchResultCollection results;
            dt.Columns.Add("GroupName");
            try
            {
                deSearch.Filter = ("(&(objectCategory=group))");
                deSearch.SearchScope = SearchScope.Subtree;
                //deSearch.SizeLimit = 10000;
                deSearch.PageSize = 1000;
                results = deSearch.FindAll();
 
                foreach (SearchResult result in results)
                {
                    dr = dt.NewRow();
                    dr["GroupName"] = result.Properties["cn"][0].ToString();
                    dt.Rows.Add(dr);
                }
                de.Close();
 
 
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (deSearch != null)
                {
                    deSearch.Dispose();
                }
                if (de != null)
                {
                    de.Dispose();
                }
            }
            
            return dt;
 
        }
 
 
Code can be downloaded here: Download

Sunday, March 13, 2011

Security Exception: The application attempted to perform an operation not allowed by the security policy

While Working on a VisualWebPart with Telerik Controls I got a Security Exception. I searched many blogs and articles, and found some information for configuring Trust Level for Code in Microsoft .NET Framework 2.0 Configuration (can be found in Administration Tools, if the .Net Framework SDK 2.0 is installed in your machine) section. But, unfortunately it didn't help me much. Finally I tried in IIS Trust Level settings and changed it to Medium level that worked just fine. Thought it helps other so posted here, below are the details of it.

Environment I tried:
SharePoint 2010, IIS 7, Telerik Controls (2010 -3 - 1317)
Error Description:
The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.



Solution (It worked for me):
Step 1:
       Go to IIS and select the webapplication you are trying (like SharePoint - 80, in my case).

Step 2:
       In the right side window you can find the options like below, select .Net Trust Levels
Step 3:
      Select the Trust Level to Medium like below.


Step 4:
     Click on Apply to commit the changes, like shown below (it resides in the same window at the right - top)
Now try in your page, the error should go away ( if the problem is with this).


Another Solution FromTelerik Site:
Cause:
Microsoft changed the default setting of the Load User Profile setting of the application pools in Windows 7 and Windows 2008 (the old was True, in IIS7.5 it is False).
Suggested solution:
Open the Advanced Settings of the Application Pool (for the web app you are using) and set the Load User Profile property to True.
Source Link: http://www.telerik.com/help/aspnet-ajax/troubleshooting.html

Other Useful Posts:

Wednesday, March 9, 2011

Get Columns Schema using ADO.Net connection

Get the details of columns for a given table using ADO.Net Connection

public DataTable GetTableColumns(string strConnection, string strTableName)
     {
         //Create connectionstring
         SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder( strConnection);
         SqlConnection con = null;
         try 
         {
             con = new SqlConnection(builder.ConnectionString);
             con.Open();
 
             // As my requirement was to just list out the columns for a table, I have used top 1 *
             SqlCommand cmd =  new SqlCommand("Select top 1 * from " + strTableName, con);
             SqlDataReader rd = cmd.ExecuteReader();
 
             //Get the Schema for the given table
             return rd.GetSchemaTable();
             
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message + ex.StackTrace);
         }
         finally
         {
             if (con != null)
             {
                 con.Dispose();
             }
         }
 
         
     }
 
Code can be downloaded here: Download

Get Database Tables Schema using ADO.Net Connection

Functionality for reading Database tables' schema using ADO.Net connection

public DataTable GetTables(string strConnection)
     {
         //Create connectionstring
         SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnection);
         SqlConnection con = null;
         DataTable dtTables = new DataTable();
         try
         {
             con = new SqlConnection(builder.ConnectionString);
             con.Open();
 
             //Get the Schema for the tables
             dtTables = con.GetSchema(SqlClientMetaDataCollectionNames.Tables, new string[] { null, null, null, "BASE TABLE" });
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             if (con != null)
             {
                 con.Dispose();
             }
         }
 
         return dtTables;
     }
Code can be downloaded here: Download

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...