Wednesday, February 13, 2013

All about SandBox Solutions

SandBox Solutions:
  • Scope of the solution is Site Collection and not entire farm.
  • Deployed and managed by Site Collection Administrators.
  • Sandbox solutions are hosted on SharePoint User Code Server Worker Process(SPUCWorkerProcess.exe) where as Farm solutions are hosted on IISWorkerProcess(w3wp.exe)
  • Sandbox solutions are uploaded to Solution Gallery(_Catalogs/Solutions).
  • No need of IIS reset or IIS App Pool recyclying.
  • Used for Web Parts, Event Receivers, Feature Receivers, Custom SharePoint Designer Workflow Activities.
  • Sandbox solutions are stored in Content Database not in GAC.
  • When a site is restored, it gets Sandbox Solutions also, if any.
  • Assemblies in a sandbox solution are included in Solution package(.wsp) and package is deployed to Site Collection 's Solution Gallery.
  • When Sandbox solution is accessed(i.e when user navigates to a page that contains web part from Sandbox solution), any assemblies in the solution are extracted from Package in the gallery and copied to the file system(C:\ProgramFiles\Microsoft\SharePoint\UCCache) of the server that is handling the sandbox request.
  • For Sandbox solutions coding, referrence the Microsoft.Sharepoint.dll from  the path, ...\14\UserCode\Assemblies. For Form solutions this dll can be  referrenced from ...\14\ISAPI folder.
  • To access resources outside a site collection from within Sandbox solution, you must implement and call a Full Trust Sandbox Proxy.
Disadvantages:
  • Can't access outside Sandbox(Ex: Database, Registry, Environment Variables)
  • Can only access same domain, other domains can't be accessed.
  • Can't be used for application pages, visual web parts, code-based workflows, unmanaged code, web service calls, SPUtility.Sendmail, RunWithElevatedPrevilages, Writing to Disk, Accessing objects in other site collection.
  • Sandbox solutions by default have code limits to 300 points.
  • Microsoft.Sharepoint.WebPartPages not allowed
Powershell Commands:

  • To upload Sandbox solution to Site Collection's Solution gallery, 
          ADD -SPUserSolution -LiteralPath .wsp 
                                               -Site

  • To Deploy(Activate) SandBox Solution,
          Install -SPUserSolution -Identity .wsp
                                                 -Site 
  • To Update  SandBox Solution,
          Update -SPUserSolution -Identity .wsp                                                  -Site 
                                                  -ToSolution .wsp