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

Wednesday, March 2, 2011

Find WorkListItems with Worklist Criteria Filter in K2 Blackpearl

While working for an utility to redirect the tasks with some custom functionality I had to search for an option to bring the WorklistItems (tasks) based on some criteria (like Folio or Title) using LIKE operator with K2 API classes WorkflowCriteria and WorkflowCriteriaFilter, but it didn’t work. Googled with some keywords and found few articles, but I could not see any simple solution from them. So did some trials on search criteria on my own finally I could figure out that if we use percentile (%) symbols with LIKE operator it works perfectly. I didn't expect this as the APIs itself should take care (as per my understanding) of this when we use LIKE operator in Criteria classes. Anyway, it is working fine for me. I thought my findings may help some folks so posted that piece of code here.


 //Create a connection string with Integrated mode
    SCConnectionStringBuilder connectionString = new SCConnectionStringBuilder();
        connectionString.Authenticate = true;
        connectionString.Host = "ServerName";
        connectionString.Integrated = true;
        connectionString.IsPrimaryLogin = true;
        connectionString.Port = 5555;

        WorkflowManagementServer workflowServer = new WorkflowManagementServer();
        try
        {
            //Create a connection
            workflowServer.CreateConnection();
            workflowServer.Connection.Open(connectionString.ToString());

            WorklistCriteriaFilter filter = new WorklistCriteriaFilter();
            // Without % symbols it won't bring any data. It is important to add
   filter.AddRegularFilter(WorklistFields.Folio, Comparison.Like, "%srinitest%");
        
WorklistItems listItems = workflowServer.GetWorklistItems(filter);
            foreach (WorklistItem item in listItems)
            {
                //Add a row  to table to show it on form
   //AddRow(item.ProcInstID.ToString(),item.Folio,item.ActivityName,     item.EventName, item.Destination, item.ProcName);

            }
        }
        catch (Exception ex)
        {
            //Handle Exception here
        }
        finally
        {
         if (workflowServer != null && workflowServer.Connection != null)
            {
                //Dispose the connection saftely
                workflowServer.Connection.Dispose();
            }
        }

You can also find the code here Download

     Hope it helps!

Thursday, February 24, 2011

Updating DataField Values within a K2 Process Instance without Admin Access

We had an issue while updating the datafield values without executing the action in the application form. If we use ProcessInstance Update method, it was obvious that we need to provide the admin rights for all the users which is not an ideal solution. So we found in the K2 Blackpearl Arcticles that we can update the Data Fields with an Action seperately created for that with in the workflow defintion. The information is described below.

 

Updating Values within a K2 Process Instance

KB Number:KB000307

Introduction

When updating values (i.e. a data field) of a process instance without completing the process in pre-0807 releases of K2 blackpearl it was possible to use the [WorkListItem].[ProcessInstance].Update() method. In K2 blackpearl 0807 the [WorkListItem].[ProcessInstance].Update() method now requires a user with process Admin rights.

The recommended way to update values of a process instance without completing it is to use the Actions["UpdateWorkItem"].Execute() method. The Action must be configured to support the updating of the work item in order to use the Execute method in the API.

Configure the Action in K2 Designer for Visual Studio

The Add Action dialogue screen contains a radio button option that enables the Action to be updated without the Worklist item being completed: Click here  to see the screen shot that shows the configuration for Save with action name UpdateWorkItem.
This radio button must be selected in order to programatically update the value within a process instance.

Update the Work Item Using the K2 API

The recommended method uses an "update" action, as opposed to firing the ProcessInstance.Update() method, so will work without Admin permissions:

SourceCode.Workflow.Client.WorklistItem wi;
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.Actions["UpdateWorkItem"].Execute();

Remember that the Action must be configured using the This action will update the work item option during the design of the process, as demonstrated in the K2 Designer for Visual Studio section above.

The following sample will now only work if it is called by a user with Admin permissions on the process:

SourceCode.Workflow.Client.WorklistItem wi;
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.ProcessInstance.Update();

 

 

 

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...