Tuesday, November 20, 2012

SharePoint : Sandboxed Solutions vs. Farm Solutions

We are almost close to end of this year and in this year I have only wrote 6 posts in SharePoint. I have not touched any SharePoint projects for like last 10 months and now I feel like I don’t know SharePoint at all. So it’s time to start learning SharePoint again, otherwise in couple of months I will ended up being a total stranger to SharePoint.

Today I am going to write about Sandbox solutions and Farm solutions. When you are creating any SharePoint solution using Visual Studio, you are prompted to select the Trust Level of the solution which is either a Sandboxed solution or a farm solution.
Untitled
Select the Trust Level
Which is either you can deploy the solution directly into the Server farm or into a sandbox. So what really is this deploying to sandbox or deploying to server farm? We are about to find it out.

Sandboxed Solution


Before learning what is a Sandboxed solution, we should learn what is a Sandbox. A sandbox is a testing environment that enables programs to access only certain resources, and that keeps problems/issues that occur in the sandbox from affecting the rest of the server environment. Basically what it does is sandbox isolates untested code from the working environment.

So when we are deploying a solution as a sandboxed solution, the solution  cannot access content outside the site collection they are deployed in. The sandboxed solution will not be able to use certain computer and network resources. Since the sandboxed solution is scoped to the site collection, we don’t really need a farm administrator to deploy the solution. A site collection administrator can do the deployment.

Sandboxed solutions are hosted in the SharePoint user code solution worker process (SPUCWorkerProcess.exe). Because sandboxed solutions do not run in the IIS worker process, neither the IIS application pool nor the IIS server must restart.

Mainly we can’t create following as a sandboxed solution.
  • Application pages.
  • Visual web parts.
  • Code-based workflows.
The following is a list of the most common things a solution running inside a sandbox cannot do,
  • Connect to resources that are not located on the local farm.
  • Access a database.
  • Call unmanaged code.
  • Write to disk.
  • Access resources in a different site collection.
  • Change the threading model.

Farm Solution


The Features in farm solutions can have scope as wide as the site collection, web application, or the whole SharePoint farm. Since Farm solutions can be scoped to Farm level, we need a Farm Administrator to deploy the solution and the assemblies in the solution always run with full trust.

Unlike sandboxed solutions, Farm solutions are are hosted in the IIS worker process (W3WP.exe) and the code in the farm solutions can affect the whole farm. When you try to retract or deploy a farm solution, the whole application pool will be recycled.

Farm solutions should be used for customizations of SharePoint administrative functions, such as custom timer jobs, custom Windows PowerShell cmdlets, and extensions of Central Administration.

For more information,
     What Can Be Implemented in Sandboxed Solutions in SharePoint 2010
     Sandboxed Solutions

Hope this helps.

Happy Coding.

Regards,
Jaliya

5 comments:

  1. thanks... its very useful for entry level person like me

    ReplyDelete
  2. Very good and elaborate description

    ReplyDelete
  3. Neat explanation..helped!

    ReplyDelete
  4. very detailed explanation........thnx

    ReplyDelete