SP 2010 Sandboxed Solutions MostafaElzoghbiSr. Software Engineer  - C# MVPMetroStar Systems
AgendaSandbox Solutions OverviewSharePoint 2007 Challenges for Farm SolutionsSharePoint 2010 Approach for Sandbox SolutionsSandbox Solutions LifecycleExecuting Code in the SandboxSandbox Solutions LimitationsSandbox Resource MonitoringLoad balancing Sandbox solutionsSolution Validation
Overview of the SandboxAllows a subset of the full capabilities in the SharePoint APISecure – enforcing the sandboxExecute in a partially trusted environmentCode executes in a special service processSubject to CASValidation frameworkProvides way to do custom farm wide validation for the deployed packagesEach solution is isolated to its site collection
Defining the SandboxSolution Administration - Quota/Blocked SolutionsSubset Object ModelExternal ProcessCode Access Security (CAS Policies)
SharePoint 2007 ChallengeDevelopers build custom solutionsAdministrators can only secure solutions with CASHard to control what is being done in custom codeBiggest cause of SharePoint support cases: custom code
SharePoint 2010 ApproachDevelopers build custom solutionsSite collection owners deploy, activate and implement the customizationsAdministrators leverage resource monitors to check site collection usageAutomatic triggers “turn off” custom solutions in a site collection that are too expensive and taxing on the server
Sandboxed Solutions Help EnterprisesSandboxed solutions are important becauseHosted environments much easier to manageReduces time to deploying custom solutionsRemoving process of getting code approved and deployed by IT (Dev-Staging-Production)Improves stability of SharePoint serversNow badly performing code isolated to site collection rather than potentially bringing down an entire server
Create/Deploy Sandbox solutiondemo
Site Collection AdministrationSolution Gallery -- _catalogs/solutionsEmpower Site Collection administrators
Sandboxed Solution Lifecycle
Managing Sandbox Solutionsdemo
Solution AdministrationCentral AdministrationBlock SolutionsQuota Templates
The Subset Object ModelSPSiteIn generalSPSite and belowNo SPSecurityNo SPSite constructionCommon namespaces not availableMicrosoft.SharePoint.AdministrationMicrosoft.SharePoint.WebControlsSPWebSPListSPListItem
A Separate ProcessUser Code Service : Started where WFE configured to run sandbox solutions.(SPUCHostService.exe)Sandbox Worker Process: where your actual code runs(SPUCWorkerProcess.exe)Sandbox Worker Process Proxy(SPUCWorkerProcessProxy.exe)
Sandbox and Code Access SecurityAspNetHostingPermission, Level=MinimalSharePointPermission, ObjectModel=trueSecurityPermission, Flags=ExecutionSandboxMy.dllwss_usercode.configOther.dllSystem DLLSharePoint DLLFull TrustSharePoint OMSubset OM
Front endBack endHost ServiceExecutionManagerSandboxing ArchitectureWorker ProcessUntrusted CodeSubset Object ModelFull Object Model
Sandboxed Solutions Process2156743Per-WFE AssemblyCacheRootSPWeb of SPSite<siteguid>\company.intranet.webpart.wsp\foo.dllSolution galleryWeb Part gallerySandboxed Worker ProcessWebParts.wsp
Types of Sandboxed SolutionsSandboxed Solutions SupportSandboxed solutions offer developers a subset of the SharePoint API available fully trusted solutionsSite collection and site scoped FeaturesMany XML constructs available: Modules, Lists, ContentTypes, etc.Client technologies to access external data – JavaScript, Silverlight etc.Offloading resource usage and access handling to client
Best Practices: Sandbox Boundaries Off-box connections, http, web services, etcADO.netEnterprise features (Search, BCS, etc.)Threading  (No complex processing)P-InvokeIOOther sitesxxxxxxx
Compiling vs. Executing Sandboxed SolutionsVisual Studio 2010uses IntelliSense tohide full-trust typesAll code is compiled against the full APIThus, no “sandbox” check at compile time… only at runtimeWorkaround: change the Microsoft.SharePoint.dll project reference to reference the sandbox’s version[..]\14\UserCode\Assemblies\Microsoft.SharePoint.dllNOTE: Switch it back before deployment!Use this as a temporary test - do not deploy code that references the sandbox’s assembly This is valid if you don’t have VS 2010 SP Power tools.MyWebPart.dllRuntimeFull Object ModelSubset Object ModelProxy
Execution vs. Compilation in SandboxDemo
Load BalancingSandboxed solutions can be run in two modesLocal ModeExecute code on the SharePoint WFELow administration overheadLower scalabilityRemote ModeExecution on back-end farm machineVia dedicated service applicationsLoad balanced distribution of code execution requests
Load balancing Sandbox Solutions & Blockingdemo
Solution Validation[GuidAttribute("34805697-1FC4-4b66-AF09-AB48AC0F9D97")]publicclassPublisherValidator:SPSolutionValidator{publicoverridevoidValidateSolution(SPSolutionValidationProperties properties){properties.Valid = [true || false];properties.ValidationErrorMessage = “no soup for you”;}publicoverridevoidValidateAssembly(SPSolutionValidationPropertiesproperties,SPSolutionFileassembly){}}
Solution Validatordemo
Monitored ResourcesYou can tweak these values to fit your need…
Manage Sandbox solution resourcesdemo
SummarySandbox Solutions OverviewSharePoint 2007 Challenges for Farm SolutionsSharePoint 2010 Approach for Sandbox SolutionsSandbox Solutions LifecycleExecuting Code in the SandboxSandbox Solutions LimitationsSandbox Resource MonitoringLoad balancing Sandbox solutionsSolution Validation
Blog: http://moustaga-arafa.blogspot.comTwitter: @mostafaelzoghbi

Mostafa Elzoghbi: SharePoint 2010 Sandbox Solutions Best Practices

  • 1.
    SP 2010 SandboxedSolutions MostafaElzoghbiSr. Software Engineer - C# MVPMetroStar Systems
  • 2.
    AgendaSandbox Solutions OverviewSharePoint2007 Challenges for Farm SolutionsSharePoint 2010 Approach for Sandbox SolutionsSandbox Solutions LifecycleExecuting Code in the SandboxSandbox Solutions LimitationsSandbox Resource MonitoringLoad balancing Sandbox solutionsSolution Validation
  • 3.
    Overview of theSandboxAllows a subset of the full capabilities in the SharePoint APISecure – enforcing the sandboxExecute in a partially trusted environmentCode executes in a special service processSubject to CASValidation frameworkProvides way to do custom farm wide validation for the deployed packagesEach solution is isolated to its site collection
  • 4.
    Defining the SandboxSolutionAdministration - Quota/Blocked SolutionsSubset Object ModelExternal ProcessCode Access Security (CAS Policies)
  • 5.
    SharePoint 2007 ChallengeDevelopersbuild custom solutionsAdministrators can only secure solutions with CASHard to control what is being done in custom codeBiggest cause of SharePoint support cases: custom code
  • 6.
    SharePoint 2010 ApproachDevelopersbuild custom solutionsSite collection owners deploy, activate and implement the customizationsAdministrators leverage resource monitors to check site collection usageAutomatic triggers “turn off” custom solutions in a site collection that are too expensive and taxing on the server
  • 7.
    Sandboxed Solutions HelpEnterprisesSandboxed solutions are important becauseHosted environments much easier to manageReduces time to deploying custom solutionsRemoving process of getting code approved and deployed by IT (Dev-Staging-Production)Improves stability of SharePoint serversNow badly performing code isolated to site collection rather than potentially bringing down an entire server
  • 8.
  • 9.
    Site Collection AdministrationSolutionGallery -- _catalogs/solutionsEmpower Site Collection administrators
  • 10.
  • 11.
  • 12.
  • 13.
    The Subset ObjectModelSPSiteIn generalSPSite and belowNo SPSecurityNo SPSite constructionCommon namespaces not availableMicrosoft.SharePoint.AdministrationMicrosoft.SharePoint.WebControlsSPWebSPListSPListItem
  • 14.
    A Separate ProcessUserCode Service : Started where WFE configured to run sandbox solutions.(SPUCHostService.exe)Sandbox Worker Process: where your actual code runs(SPUCWorkerProcess.exe)Sandbox Worker Process Proxy(SPUCWorkerProcessProxy.exe)
  • 15.
    Sandbox and CodeAccess SecurityAspNetHostingPermission, Level=MinimalSharePointPermission, ObjectModel=trueSecurityPermission, Flags=ExecutionSandboxMy.dllwss_usercode.configOther.dllSystem DLLSharePoint DLLFull TrustSharePoint OMSubset OM
  • 16.
    Front endBack endHostServiceExecutionManagerSandboxing ArchitectureWorker ProcessUntrusted CodeSubset Object ModelFull Object Model
  • 17.
    Sandboxed Solutions Process2156743Per-WFEAssemblyCacheRootSPWeb of SPSite<siteguid>\company.intranet.webpart.wsp\foo.dllSolution galleryWeb Part gallerySandboxed Worker ProcessWebParts.wsp
  • 18.
    Types of SandboxedSolutionsSandboxed Solutions SupportSandboxed solutions offer developers a subset of the SharePoint API available fully trusted solutionsSite collection and site scoped FeaturesMany XML constructs available: Modules, Lists, ContentTypes, etc.Client technologies to access external data – JavaScript, Silverlight etc.Offloading resource usage and access handling to client
  • 19.
    Best Practices: SandboxBoundaries Off-box connections, http, web services, etcADO.netEnterprise features (Search, BCS, etc.)Threading  (No complex processing)P-InvokeIOOther sitesxxxxxxx
  • 20.
    Compiling vs. ExecutingSandboxed SolutionsVisual Studio 2010uses IntelliSense tohide full-trust typesAll code is compiled against the full APIThus, no “sandbox” check at compile time… only at runtimeWorkaround: change the Microsoft.SharePoint.dll project reference to reference the sandbox’s version[..]\14\UserCode\Assemblies\Microsoft.SharePoint.dllNOTE: Switch it back before deployment!Use this as a temporary test - do not deploy code that references the sandbox’s assembly This is valid if you don’t have VS 2010 SP Power tools.MyWebPart.dllRuntimeFull Object ModelSubset Object ModelProxy
  • 21.
  • 22.
    Load BalancingSandboxed solutionscan be run in two modesLocal ModeExecute code on the SharePoint WFELow administration overheadLower scalabilityRemote ModeExecution on back-end farm machineVia dedicated service applicationsLoad balanced distribution of code execution requests
  • 23.
    Load balancing SandboxSolutions & Blockingdemo
  • 24.
    Solution Validation[GuidAttribute("34805697-1FC4-4b66-AF09-AB48AC0F9D97")]publicclassPublisherValidator:SPSolutionValidator{publicoverridevoidValidateSolution(SPSolutionValidationProperties properties){properties.Valid= [true || false];properties.ValidationErrorMessage = “no soup for you”;}publicoverridevoidValidateAssembly(SPSolutionValidationPropertiesproperties,SPSolutionFileassembly){}}
  • 25.
  • 26.
    Monitored ResourcesYou cantweak these values to fit your need…
  • 27.
  • 28.
    SummarySandbox Solutions OverviewSharePoint2007 Challenges for Farm SolutionsSharePoint 2010 Approach for Sandbox SolutionsSandbox Solutions LifecycleExecuting Code in the SandboxSandbox Solutions LimitationsSandbox Resource MonitoringLoad balancing Sandbox solutionsSolution Validation
  • 29.

Editor's Notes

  • #2 MostafaElzoghbiMetroStar SystemsSr. Software EngineerMCAD,MCSD,MCTS,C# MVPhttp://moustafa-arafa.blogspot.com
  • #9 In this demo will show:Use VS 2010 to create sandbox solutions.Deploy and configuration on the Sandbox solutions.Test deploy the sandbox solution.Go through the prerequisites to enable user code service on your farm. Enable User code service in your farm-- Tips: Don’t use WSP Builder menu for Sandbox solutions, use Retract,Deply…etc options from the Project properties menu.Try to do a change in UI and redeploy your wsp, the old webpart UI still cached, Resolve: Remove the webpart from webpart gallery.
  • #11 Inert: Not effectiveIt’s called also : Sandbox Solution model process: 4 phases: Upload stageActivation stageDeactivation stage: pages with web parts will shows an error message.Delete Stage: cant be deleted if the solution is activated. If deleted it goes to the site recycle bin and can be deleted or restored.Upgrade Stage
  • #12 Activate/ Deactivate/ Delete and restore.
  • #16 Path for the configuration for the sandbox solution is:C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14CONFIGFile name: wss_usercode.config
  • #19 How to get VS 2010 SP power tools:From VS tools -&gt; Extension manager and Top Ranked Extensions.
  • #22 Open SPSNYCDemo2Try to build - &gt; Get an error since the SPSecurity in not available in sandbox solutions.Change the project target to farm solution and try to build -&gt; 0 errors.This is only applied on: VS 2010 Power tools. This is your validation for Sandbox solutions.Details:http://visualstudiogallery.msdn.microsoft.com/en-us/8e602a8c-6714-4549-9e95-f3700344b0d9
  • #24 To show how to load balance the sandbox solutions:Central AdministrationSystem SettingsManage User Solutions All user requests will be executed on the same machine - &gt;Users’ requests are routed using solution affinity.Try to blocksharepoint solution and navigate to the webpart page. You will see the block message is appearing.
  • #26 Farm solution.
  • #27 Only 14 metric:http://msdn.microsoft.com/en-us/magazine/ee335711.aspx
  • #28 From Central admin -&gt; application management -&gt; Configure quotas and locks