SharePoint 2010: permission policies

In a SharePoint it's possible to have many site collections inside a single web applications. If it could be difficult to manage permissions per each site collection, keeping them property synchronized could be a nightmare. Permission policies help to solve this topic, allowing to manage permissions for a subset of users or groups.

In fact, permission policies provide a centralized way to configure and manage a set of permissions that applies to only a subset of users or groups in a Web application.

To specify a permission policy:

  • you must be in the Farm Administrator security group on the computer running the Central Administration;
  • select the desired web application, and in the ribbon press the User Policy button, and then press the Add User button;
  • select the desired zone;
  • select specific users or groups;
  • select the desired permissions.

For anonymous users, once enabled them in the web application, it's possible to specify the following user policies:

  • None: no user policy defined;
  • Deny Write;
  • Deny All: it's like revoking access to anonymous users.

It's possible to find more information in the article Manage permission policies for a Web application (SharePoint Server 2010).

SharePoint 2010: creating custom Service Applications

SharePoint 2010 drops the old concept of SSP (SharePoint Service Providers) and introduces the concept of Service Applications.

They are a way of exposing WCF services leveraging all the benefits of the SharePoint platform, for example load-balancing and high-availability using multiple front ends.

Here are some links:

SharePoint: SPPersistedObject and hierarchical object store

SharePoint has the concept of SPPersistedObject and hierarchical object store.

The key concepts are:

  • inherit your configuration class from SPPersistedObject, give it a Guid and mark the needed fields (not properties) as Persisted;
  • hierarchical object store means that every object has a parent, so when the parent is deleted, all its children are deleted too;
  • every object has to have a unique name in the context of its parent;
  • it can be rather tricky to save collections of SPPersistedObject children, in this case the class SPAutoSerializingObject could be considered instead.

It's possible to find a very complete and detailed explanation in the article The skinny on SPPersistedObject and the Hierarchical Object Store in SharePoint 2010.

SharePoint: property bags

Property bags are used in SharePoint to store configuration values in the form of hash tables (key-value) at different levels: SPFarm, SPWebApplication, SPWeb and SPList.

They are simply used in the form of <my object>.Properties.

There is no default user interface to manipulate them, but it's possible to use SharePoint Designer 2010 (via Site Options | Parameters), SharePoint Manager 2010 and the more specific SharePoint Property Bag Settings 2010, or modify them by PowerShell too.

For other articles about them:

SharePoint 2010: the Developer Dashboard

SharePoint 2010 introduces the Developer Dashboard. It's a debugging tool used to understand what is happening during the page processing of SharePoint pages, for example for database access and web-part processing.

To activate the Developer Dashboard following the instructions shown in the article Using the Developer Dashboard, but briefly they are:

  • via stsadm:
    • stsadm -o setproperty -pn developer-dashboard -pv ondemand
  • via powershell:
    • (Get-SPFarm).PerformanceMonitor.DeveloperDashboardLevel = ”OnDemand”
  • via code:
    • SPWebService svc = ContentService.DeveloperDashboardSettings;
    • svc.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.OnDemand;
    • svc.DeveloperDashboardSettings.Update();

The three possible display statuses are: On, Off and OnDemand. When the status is OnDemand, it's possible to activate it from an icon in the upper right corner, but even On could be helpful, for example when the master page is corrupted.

The very intresting thing is that it's possible to extend the Developer Dashboard to show have even the custom code appear in the Developer Dashboard, and this can ben accomplished using the SPMonitor class, like in this example:

protected void Page_Load(object sender, EventArgs e)
    using (SPMonitoredScope scope = new SPMonitoredScope(this.GetType().Name)
        do some code here...

        // eventually use inner scopes too
        using (SPMonitoredScope scope = new SPMonitoredScope("Inner Scope"))
            and do some other code here...



SQL Server: delete all rows of all tables to empty a database

In SQL Server it's possible to empty a database deleting all rows of all tables with the following simple script I've found in the blog post T-SQL Trick for Deleting All Data in Your Database:

-- disable referential integrity

EXEC sp_MSForEachTable ' IF OBJECTPROPERTY(object_id(''?''), ''TableHasForeignRef'') = 1 DELETE FROM ? else TRUNCATE TABLE ? '

-- enable referential integrity again

But if the database contains identity columns and you want to reset them, you can visit the forum topic Truncate All Tables, answer of 06/13/2007 at 11:38:52, or download directly the code from the file EmptyAllTables.sql.txt.

async and await keywords in C# 5

The new version of the C# language, the version 5, introduces native support to async programming.

Async programming has always been available since the first version of .NET and C#, but now the development is really simplified, because the compiler is taking care of all the burden to deal with it.

To understand this semplification, and explain the support that the compiler is giving to the developer, we can summarize in the following points:

  • when you need to execute a lenghty operation, use the await keyword;
  • mark methods with await keywords with the async keyword;
  • logically, what the compiler will do is:
    1. generate the first part of the method up to the async call;
    2. the async call will be done passing as callback another "hidden" method,
    3. that will be defined with the remaining of the body content, and will be able to consume the output of the async call;
  • pratically, this construction makes use of the Task<T> class, where T is the type of the output of the async call;
  • one final note: in a async method, multiple await are possible.

As reference, there are the following articles: