Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Tuesday, October 9, 2012

Must have tools for SharePoint 2010 developer


Developer Environment Setup
  • Install Windows Server 2008 R2
  • Install SQL Server 2008 R2 Dev
  • Install Visual Studio 2010 Professional - Customize all remove all the unnecessary ones like the SQL Express.
  • Install SharePoint 2010 Enterprise.
  • (Optional) Install the latest Cumulative Update. June 2012 as of now.  

Note: Ensure to run the windows updates after every major installation.



Install all the required VS extensions:

Third party tools:

Wednesday, July 25, 2012

Setting Site Permissions during the Site Provisioning


Setting custom permissions during site provisioning can be a confusing affair. With some investigation, I was able to get the concepts clear. 
Below is the design we used for Groups and permissions in one of our projects during the site provisioning. Hope it helps you in your projects as well.

Note: All groups are created at the Site collection level. They will be visible at all the webs that will be created under it.

SiteCollection Feature Activation
1. Create custom RoleDefinitions (Permission Set) {ViewEditRD, ViewAddEditRD} at the Site Collections. This will get inherited at all the webs. Don’t get confused with the Permission breaking at the Web level.
2. Create an Admin group (SiteAdmins) at the SiteGroups collection. This will be used to provide admin activities on the Sub webs or Lists that will undergo inheritance breaking.

New Project Provisioning
1. Create the Project with Inheritance of the Permission broken.
2. Create the Custom Groups {PMGroup, TeamMebersGroup} for every Web created.
3. Associate the Custom Groups created at the Site Collection with Read permissions.
4. Associate the Custom Groups created at the Web Level with appropriate RoleDefinitions {ViewEditRD/ViewAddEditRD}. SPRoleDefinition defines the set of permissions permitted on SharePoint objects. 
5. Associate the SiteAdmins group at the Administrator role at the Web level.
6. Break the Permissions at the List level and apply the Required RoleAssignments based on the RoleDefinition and Groups. SPRoleAssignment class is used to bind together a Group and RoleDefinition with a SharePoint Object (web, list or a document library). 


Thursday, March 8, 2012

Some best practices of developing SharePoint 2010 applications



Came across some nice videos on best practices from Ted Pattison. Here is the gist of what he suggests.

Development
  • Use Site template instead of the site definition. Hell during the upgrades from one version of SP to another.
  • Deploy the site templates as sandboxed solution in the staging/test environment to check out the bottlenecks and depending on the needs deploy them in production as sandboxed or farm based.
  • Use Feature Stapling. element to staple a feature to a site definition.
  • Version Features and anticipate for feature upgrades.
  • Hide the Features that have been stapled as hidden. Use the Visual studio properties windows to hide them. This ensures that they are not seen by the site admins.
  • Keep in mind about various cycles of Activation and Deactivation. Deactivation leaves behind the list instances and next time activations will break during the deployment. Ensure to write appropriate code to either delete or backup previous versions before deleting them.


Testing and Deployment.
  • Use the SPDisposeCheck utility sparingly.
  • Ensure to use the keyword using() especially to SPSite object to let the .net framework take care of the disposing. Do not dispose the SPSite object created by others that is received through the event receivers or anything like that. Ex: properties.parent.site
  • Test your environment without any SDKs installed. Probably a VM or something would be good. Keep your QA environment with at least two boxes. One for the Web/App and another for the DB Server.
  • Test your QA machines on debug mode to catch any unknown errors.
  • If you are deploying a farm based solutions prefer to use a script like PowerShell to install them.
  • Updates to web.config needs to be automated. For safe control entries you can add data to the manifest file. However for other entries use the SP Object model. See some methods of updating web.config http://msdn.microsoft.com/en-us/library/ms439965.aspx  / http://msdn.microsoft.com/en-us/library/bb861909.aspx








Sunday, March 4, 2012

Extending the debug session in SharePoint 2010


Error Message
The Web server process that was being debugged has been terminated by Internet Information Services (IIS). This can be avoided by configuring Application Pool ping settings in IIS. See help for further details.


Resolution
By default, the IIS application pool waits 90 seconds for an application to respond before it closes the application. This process is known as "pinging" the application. To resolve this issue, you can either increase the wait time or disable application pinging entirely.


To access the IIS app pool settings

  1. Open IIS Manager.
  2. In the Connections pane, expand the SharePoint server node and click Application Pools.
  3. On the Application Pools page, select the SharePoint application pool (typically "SharePoint - 80") and then, in the Actions pane, click Advanced Settings.
  4. To increase the wait time before IIS timeout, change the value of Ping Maximum Response Time (seconds) to a value larger than 90 seconds.
  5. To disable IIS pinging, set Ping Enabled to False.



for more information on the troubleshooting in SharePoint 2010 
http://msdn.microsoft.com/en-us/library/ee231594.aspx

Friday, February 10, 2012

SharePoint 2010 Scrollbar is not showing up


There are cases where your SharePoint pages renders without a vertical scroll bar or it is disabled. However, if you hold your left button down and drag downwards you will be able to see the rest of the page.
The chances of this scenario showing up are higher on non-IE browsers. Mostly occurs because of your custom master page. 


We have tried different articles out there on the internet. Here is a simple hack that did the trick. 


//Just put the below snippet in the footer control so that it will be called on all the pages.
 function adjustDivSize() {  
     var winHeight = $(window).height();  
     $('#s4-workspace').css("height", winHeight);  
   }  
 $(document).ready(adjustDivSize);  
 $(window).resize(adjustDivSize);  

Thursday, February 9, 2012

Cache implementation for your Web & WCF resource


There are different ways of implementing the caching.
1.       At the server, where you store data in-memory using the ASP.Net Cache / Application classes.
2.       In the client (Browser). This definitely gives more advantage in terms of performance.

This article describes in detail about the second type of caching.


What are the resources that can be cached?
Static resources like html, scripts - js, style sheets – css, images – gif, jpg etc
Ex: http://www.domain.com/images/banner.jpg
Dynamic resources which are REST based urls  - if you think that these resources don’t change their data very frequently then they can be a good candidate for caching.
Ex:

                                                               
What do we intend to save by caching on the browser?
Loading the server to fetch the data and pass it across
Even making an http request to the server. There are other ways to save the number of requests to server by using minification process. Where we can merge several js/css files into single file. You can read my previous articles to know more about it.


Implementing Caching
This is simple by adding Expires Header (when you know exactly when to expire) to the IIS. http://technet.microsoft.com/en-us/library/cc770661(WS.10).aspx
You can also use the Max Age header when you are not sure of the number days you need to cache the resource. The above link describes for both.


Challenges
Finding the exact Expires/MaxAge becomes hard as we will not be able to predict our bug fix cycles due to hot fixes etc.. specially in case of smaller projects.


Solution
Two common solutions both deal with manipulating the URL:
1.       Manipulate the calls to the resource by adding a query string. This requires to do a find a replace to all the locations where the resource is being referenced. Ex: http://www.domain.com/app/images/banner.jpg?rev=2345 . This becomes a painful process to manipulate it every time a resource is changed. There are very high chances that we may miss out modifying a revision query string. This also has some minor drawbacks that some proxy servers don’t cache urls which contain query string.

For REST based WCF Service, add this piece of code before the response.
OutgoingWebResponseContext ctx = WebOperationContext.Current.OutgoingResponse;
ctx.Headers.Add(HttpResponseHeader.CacheControl, String.Format("public, max-age={0}", maxAge)); //in seconds.

2.       The second more robust solution “Fingerprinting” is to inject some kind of hash into the url. Ex: http://www.domain.com/CBUSTZqTMzNV8qFU/0.jpg
Here the part of the url before the file name is the fingerprint or a hash generated based on the contents of the resource being accessed. This requires that we use some mechanism like a URL Rewrite module to do a Rewrite of requests. Ex: Search for a pattern (.*)/CBUST[A-F0-9]{32}(/.*) and do a rewrite to {R:1}{R:2} For more information on URL Rewrite http://www.iis.net/download/urlrewrite
In your aspx files, you will reference your resources like <script type="text/javascript" src="<%=Utilities.CacheBusterUrl("/_layouts/scripts/jquery-1.4.3.min.js"%>">script>

Add this piece of code in your Page_Load if it is a page.
if (!this.Page.IsPostBack)
{
this.DataBind();
}

If it is a user/web control then ensure that the page that is adding this user/web control has the above piece of code.

The Fingerprinting method has its own limitation that any resource referenced in .css file or being rendered from SharePoint library cannot be cached like this.

Implementation of the CacheBuster utility is as follows.
    public static class Utilities
    {
        private static Hashtable Md5Map = Hashtable.Synchronized(new Hashtable());

        public static string CacheBusterUrl(string sourceUrl)
        {
            try
            {
                string filesystemPath = HttpContext.Current.Server.MapPath(sourceUrl);
                string fileMD5;
                lock (Md5Map.SyncRoot)
                {
                    if (Md5Map.ContainsKey(filesystemPath))
                    {
                        fileMD5 = Md5Map[filesystemPath].ToString();
                    }
                    else
                    {
                        fileMD5 = CreateHash(filesystemPath);
                        Md5Map.Add(filesystemPath, fileMD5);
                    }
                }
                return BuildCacheBusterURL(sourceUrl, fileMD5);
            }
            catch (Exception ex)
            {
                return sourceUrl;
            }
        }
    }


Security Warning
Be aware that if your Web Application stores cookies then caching resources at the proxy servers can be a security threat. So make sure to use https whenever you decide to store cookies.

Tuesday, May 10, 2011

Production Setup of SharePoint 2010 and SSRS Load balanced with NLB

Production Setup:
  1. Two Web Front Ends (Network Load balanced) - No Central Administration
  2. Two Application Servers (Includes SharePoint, Power Pivot and SSRS Servers - Network Load balanced) - Both Servers contain Central Administration
  3. Clustered Database (Active-Passive Mode)
  4. SAN (Later switched to NAS) for storage of terabytes of Images. Product involves storing a lot of images.
All machines were Windows Server 2008 R2 with imaginably very high configuration on memory and hard drive.
SharePoint does not require you to load balance the Application Server, however in this specific case the requirement was to have high availability of the application and provision for scaling later.

First configure the DB in a clustered mode. This was already done by the DBA, so I will not cover it here.
Next, configure the Report Server in a scale out mode over a NLB

To setup and configure the SharePoint, we followed the steps mentioned in the below article with a few exceptions (Configuring Search was not required).

We made sure that all the Service applications (Excel, Power Pivot & Secured Store Service) were provisioned on both the Application Servers.

Make sure to have only the required services in the WFE. You can turn off all the Service Applications that are provisioned on the Application Servers.
Next, setup the Power Pivot on both the Application Server and re-configure the Power Pivot Service Application from the Central Administration.
http://msdn.microsoft.com/en-us/library/ee210616.aspx

Once the Configuration was done, most of the steps were custom. 

Few things that is worth of mentioning:
  1. Ensure that your domain name and web site names are not the same. We had a very hard time reverting it as users internally to the company were not able to use the Web Site. The reason, was all the requests to the site was going to the Domain Controller instead.
  2. When you are creating a Web Application, use the website name for Public URL Ex: http://mywebsite.domain.com instead of the default, Application Server name (filled by default). We could not find a way to revert this.
  3. Ensure to make appropriate DNS entries so that the web site is really internet facing. Your administrator may want to make entries in the Name server, to map the website name to the local load balancing web server, so that users (employees) within the domain need not go through internet.
 Hope this should be a good start. Good Luck! on your setup.

Thursday, May 5, 2011

Can't find my SharePoint Web page on IIS?

Coming from a background of ASP.net, we are used to going to the IIS Manager and locating a web page file. In SharePoint, try finding it. You will be surprised. We usually map the URL relative to the Application directory of the WFE.
When you create a new Web Application in SharePoint it creates an entry in the IIS with the application by default being hosted on the Physical Directory C:\inetpub\wwwroot\wss\VirtualDirectories\ 
All Standard Pages/Pages that you created in the SharePoint Console, ideally should have been placed in this directory, but, instead SharePoint stores them in the Content database.


Then you must be wondering how SharePoint manages to find the correct page through the URL. 
ASP.Net came up with a new concept of VirtualPathProvider. To allow users to implement custom storage of the files (web pages) without affecting the way users access web pages. SharePoint has provided a custom implementation through SPVirtualPathProvider that connects the URL with the appropriate page from the Content Database.
The SPVirtualPathProvider class works together with another class named the SPPageParserFilter to supply processing instructions to the ASP.NET page parser. For example, the SPPageParserFilter component controls whether the ASP.NET page parser compiles the ASP.NET page into an assembly DLL or whether it processes the page in a no-compile mode that is introduced with ASP.NET 2.0




Not all standard pages come from SharePoint Content database. Some pages are hosted within the SharePoint root folder. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\
SPVirtualPathProvider will know from where a particular page has to be picked up from (File System vs. Database). These kinds of pages are called as Ghosted Pages. The pages that come from Content database are called UnGhosted pages. These are customized pages of the standard pages.


SharePoint version of the life cycle is depicted in the below image. They integrate with the ASP.Net runtime seamlessly by adding the SPHttpApplication (HttpApplication replacement for the ASP.net) containing a Module SPRequestModule with a couple of common ASP.Net modules. This finally uses the SPHttpHandler (SharePoint implementation of HttpHandler) to process requests.
Global.asax would contain a directive as 
<@Application Inherits="Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication" >
Http Module and Http Handers will be registered with the application through the Web.Config.

A quick view of the IIS brings us to a couple of Virtual Directories of a SharePoint web application. If you follow the Physical path of these they point to the Root folder.
Note: The image is from the MOSS. However, they are pretty much the same with a few additions in SharePoint 2010.
  • _vit_bin : Provides Windows SharePoint Services with a way to expose DLLs and .asmx Web service files at a path within the URL space of a Web application. 
  • _controltemplates : Provides a repository for deploying ASP.NET user controls that can be used within pages. 
  • _wpresources : Provides a repository for resource files that are deployed along with Web Parts.
  • layouts :  Provides the repository for application pages. 
There is only one version of an application page scoped at the farm level, it can be compiled into a single DLL and loaded into memory once for each Web application. 
An application page, such as settings.aspx, can be accessed by adding its relative path within the _layouts directory to the end of a site’s URL
http://Litwareinc.com/_layouts/settings.aspx 
http://Litwareinc.com/sites/Vendors/_layouts/settings.aspx  
http://Litwareinc.com:1001/sites/Accounting/_layouts/settings.aspx