Sunday, August 26, 2012

web Content Management WCM for Sharepoint 2010

Ted pattison thanks for the below steps to deploy branding :



 above sol is an Empty Sharepoint Project and the .master and .css file and .jog files were added using modules :

The idea here is to apply branding at the site collection level
 and to any site regardless of whether  its a publishing or non - publishing site thats there for us .

U can also deploy a SB sol at the farm level.

Since its a SandBox sol we have the following situation :
a sandboxed solution cannot deploy files within the SharePoint root directory or any other location on the file system of the web server. That means you cannot deploy branding files to familiar locations that are commonly used in farm

solutions, such as the IMAGES directory or the LAYOUTS directory. You must instead provision branding files, such as images and CSS files, inside the content database within the scope of the hosting site collection.
So its a matter of provisioning of the  branding

sandboxed solutions, it is important to distinguish between Features that activate at site collection scope and Featuresbthat activate at site scope. This is because a Feature that is configured to activate at site collection scope is automatically activated when the user activates the sandboxed solution that contains it. On the other hand, Features that

are configured to activate at site scope are not automatically activated. They must be manually activated by the user ornactivated by using custom code. For this reason, you should generally design a sandboxed solution with at least one

Feature configured to activate at site collection scope.
So we take the approach of creating /adding MODULE elements in the  empty SP project.

The 1st MODULE is for adding a SharePoint Master page and placing it in the /_catalogs/masterpage in MasterpageGallery

folder
So u add a sample.txt file and then copy the contents from the V4.master file and
and paste the same here .
make some twaeks .
Then make changes to the elements .xml file foir the module for the    
FileProperty(
     
      )
and Url (Url="_catalogs/masterpage" )for the the .master file that gets developed here .

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MasterPageGallery" Url="_catalogs/masterpage" >
    <File Url="MyCustomLayout.master" Type="GhostableInLibrary" >
      <Property Name="UIVersion" Value="4" />
      <Property Name="ContentTypeId" Value="0x010105" />
    </File>
  </Module>
</Elements> 
 
 
In the  

The 2nd MODULE is for adding a SharePoint Master page and placing it in the /_catalogs/MasterpageGallery folder
you do not have to modify the Elements.xml file manually in this case.

Then you add  a below shown Feature Receiver to Apply Branding Attributes :
to deploy a custom master page and a custom CSS file
You uncomment and code the
FeatureActivation
public override void FeatureActivated(
                       SPFeatureReceiverProperties properties) {
  SPSite siteCollection = properties.Feature.Parent as SPSite;
  if (siteCollection != null) {
    SPWeb topLevelSite = siteCollection.RootWeb;

    // Calculate relative path to site from Web Application root.
    string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
    if (!WebAppRelativePath.EndsWith("/")) {
      WebAppRelativePath += "/";
    }

    // Enumerate through each site and apply branding.
    foreach (SPWeb site in siteCollection.AllWebs) {
      site.MasterUrl = WebAppRelativePath + 
                       "_catalogs/masterpage/Branding101.master";
      site.CustomMasterUrl = WebAppRelativePath + 
                             "_catalogs/masterpage/Branding101.master";
      site.AlternateCssUrl = WebAppRelativePath + 
                             "Style%20Library/Branding101/Styles.css";
      site.SiteLogoUrl = WebAppRelativePath + 
                         "Style%20Library/Branding101/Images/Logo.gif";
      site.UIVersion = 4;
      site.Update();
    }
  }
} 
 
 
public override void FeatureDeactivating(
                       SPFeatureReceiverProperties properties) {
  SPSite siteCollection = properties.Feature.Parent as SPSite;
  if (siteCollection != null) {
    SPWeb topLevelSite = siteCollection.RootWeb;

    // Calculate relative path of site from Web Application root.
    string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
    if (!WebAppRelativePath.EndsWith("/")) {
      WebAppRelativePath += "/";
    }

    // Enumerate through each site and remove custom branding.
    foreach (SPWeb site in siteCollection.AllWebs) {
      site.MasterUrl = WebAppRelativePath + 
                       "_catalogs/masterpage/v4.master";
      site.CustomMasterUrl = WebAppRelativePath + 
                             "_catalogs/masterpage/v4.master";
      site.AlternateCssUrl = "";
      site.SiteLogoUrl = "";
      site.Update();
    }
  }
} 
 
 
The AlternateCssUrl property is used to link the pages in a site to the custom CSS file named Styles.css.

Alternative approach of linking to a custom CSS file by using the CSSRegistration control. For example, you can add the 

following CssRegistration element to the head section of a custom master page to link to a CSS file inside the Style 

Library.
XML

  name="<% $SPUrl:~sitecollection/Style Library/styles.css %>" 
  After="corev4.css"
  runat="server"
/>

One benefit of using the CssRegistration control over the AlternateCssUrl property is that it enables you to link to more 
than one CSS file. A second advantage is that you can use the CssRegistration control in individual pages for scenarios 
where you have a CSS file that is used by some, but not all, pages within a site. However, using the CssRegistration 
control also has a downside because it relies on the $SPUrl expression, which requires the hosting farm to be running 
SharePoint Server 2010

For SharePoint 2010 UIVersion = 4 


Once the above is don we  have  to think of applying this branding to any new site that gets created 
from this site collection
We solve this by Adding an Event Receiver .
SharePoint Server 2007, you would have to use Feature stapling. However, SharePoint 2010 adds support for a new event 
named WebProvisioned, which makes the job much easier.

Select an Event Receiver of type Web Events. At the bottom of the dialog box, under Handle the following events, select 
the A site was provisioned option.
file, which contains the Receivers element that is required to register this event handler in the current site 
collection. The benefit of adding this event is that it occurs each time a new child site is created. This makes it 
fairly easy to write the code that copies the relevant SPWeb properties from the top-level site to the new child site. 

The following shows the code that is required.
 
using System;
using Microsoft.SharePoint;

namespace Branding101.ChildSiteInit {

  public class ChildSiteInit : SPWebEventReceiver {
    public override void WebProvisioned(
                           SPWebEventProperties properties) {
      SPWeb childSite = properties.Web;
      SPWeb topSite = childSite.Site.RootWeb;
      childSite.MasterUrl = topSite.MasterUrl;
      childSite.CustomMasterUrl = topSite.CustomMasterUrl;
      childSite.AlternateCssUrl = topSite.AlternateCssUrl;
      childSite.SiteLogoUrl = topSite.SiteLogoUrl;
      childSite.Update();
    }
  }
}
 
SharePoint Designer does not let you directly edit the templates for master pages, such as Banding101.master, 
or the templates for CSS files, such as styles.css. Instead, when you are working in SharePoint Designer 2010 you are 
making customization changes to provisioned instances that are stored inside the content database. However, this does not 
pose much of a problem because you just have to know how to copy and paste from SharePoint Designer 2010 into Visual 
Studio 2010.
 


=======================================
i didn't know much about WCM till i was asked to create a publishing site and then I had to open the same from the SPD. Once i go and try to open the Master pages for that site  I see that I can edit the master page and  .

Randy Drisgill and Scott hillier article


v good :
add/move/delete  web parts from SP site Master page

http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=794

http://sharepoint-insight.blogspot.in/2008/09/sharepoint-using-splimitedwebpartmanage.html

in mysite host we have the mysite.master which can be used.
startermasterpages.codeplex.com u can download the master pages.

Global navigation at the top that can be designed at the top.
From the SP designer we can get the list of  the master pages that are there for
the site that we have opened the designer for .
Among them there will be the v4.master.
There u will find a lot of 

using the  s4_die css class
so u can bunch all of these place holders in one place.
So in the mymaster.master page u will have bunched them togthere and
the main thing  is

these are the tags that  are more important and usefull to us.                                                                            
Among the folders that are there is the StylesLibrary folder.
All the css and the .ico,.js files that will be required by our branding should be placed
in this folder .
 
To get the relative location of .css files in the master page  or other resources we can use the
SPUrl:~sitecollection/style library/site1/mysite.css

You can right click on the master page that u are developing and apply the same to
custom  and site pages.
Site pages : Site settings/central admin etc.
custom pages can be the search/profile pages etc. that u are changing.

Delegate Control : Enables u to put a control in a site. However that control can be overridden
by a feature.So in our case we can inject a control using the delegates.You can code a  feature that will override the targeted delegate control with the custom control.

 Example we can change the default search with a a different search. Hence here u can use the
delegate

 we get the question to change the navigation at the top or bottom.


This the GlobalNavigationLink and that's what is played around  here.

We have to load a custom control instead of the ootb control.Hence comes in the Feature that requires deployement .
in the `14/template/control template/myTopNav.ascx
The feature is in the 14/template/features/CustomMysiteNav folder/feature.xml,elements.xml

The feature file has the normal things like title/scope/ etc. and the elementmanifest points to the
element.xml.

In the element.xml file
Sequence=10
ControlSrc = "~/Conrol ../template/myTopNav.ascx "

In the above line of code  the sequence given is supposed to be higher than that of the
OOOOTB  control asscoaiated with the globalnavigation id.
If you goto the v4.master you will find a delegate control having the same Control id="GobalNavigation"
and that what gets overridden here.

So the 2nd part of the presentation is all about the  packaging the branding into a feature.
Then stapling the feature into we Provisioning in this case  the provisioning of the Personal site
SPSPERS#0 template.

feature site template associations (also known as “feature stapling”), master pages, is the method.

Now we create a  Feature and that will,be used for activating the master pages /styles etc.
The Feature activated method is overridden  and there we can write the code for the setting the
MasterURL and Custom mAsterurl
WITH THE master pages file  that is placed at a certain location in the _catalog folder.
the style sheets are placed at the /Style Library /Folder. the css,logo files are placed using a
feature out there .

ADDING/deleting/moving web parts in a MySite
--------------------------------------------
tricky because there is a timing issue involved .
Because when u are moving /changing the master pages u have to make sure that the page exists before the page runs.
So u have use a server control that does  a postback when the page loads and hence it is made  sure that the page exists.Make sure that the code runs only after the page loads
tinyurl.com/MysiteDeploy

Lots of complexity here for WebParts are displayed to the user depending on the user profile that is plugged in here for that user.

 Mysite is the backbone of the social content of the SharePoint.





Wednesday, August 15, 2012

SharePoint 2010 Authentication Security


Autrzn
SP is neutral to any identity provider.
As long as SP is provided with a SAML token which matches the industry standards settings, it accepts the same .In SP you will get multi-auth web applications i.e supporting various authzn. providers.This will show up in the Login page.


For custom Access Denied page :
Central Admin -- default login page or you can specify URL for the page that u have made.
SP is always running the STS(single token service) under the covers for us.


you can change the classic mode authn to Claims mode using Powershell.
Claims Identities provider: i.e. AD. whos is saying the username/group and the password is correct.
 






Claims Provider:
Provides claims that are adding  extra attributes/claims to the user SAML token based on business rules.depending on the token values u authrz
Claims provider tell SP : here is some info  abt the current user and trust me its correct .
Here is the info abt the user and based on the database i will populate some claims.
Its like HTTP module/handler in .Net . once the identity provider says that this is Sujoy the SP calls all the custom claims provider/providers and in that code you can add claims(eg Manager/Member/Geaography) to what you call is a  SAML token.
This is called claims augmentation.


AuthRiz.:

2 ways to accomplish the same :

People Picker
When u config claims using (FBA , Win Auth) these claims are going to show up in the ppl picker.So u can authrz depending on the claims.
The code that he has written generates 2 claims : manager, member claim.
So in can Authz according to what comes up as claim
In the code there is Linq to SQL as SPMetal has been used for getting data from the database that contains user data .


The business req  as shown in the video:
 if the user comes in thru  windows auth then the user is a manager
Else
 the user comes in thru the FBA then  the user needs to be verified against the db.i.e.member





Uses of Claims

For Datagrid to display all claims that are there on the site
 After the code walkthru.He is authorizing the data based on claims.

2 scenarios ;

Scenario 1 :if its  SP object (site/list /folder/item) then you can use the ppl picker.

Scenario 2 :However,if this is a webpart  and the ppl picker is not best for that.(cant secure a webpart).here u can inspect claims for the current user  and then render information accordingly.This is a authrz piece that will be v helpful.Uses custom code and then you can inspect the claims


Hence there are 2 things that claims provider can do :
1>Augment the token/claim and make that show in the  people picker.
2>Claims Picker.



Steve Peschka -- blogs v usefull.
msdn.microsoft.com/en-us/library/ff699494.aspx

When some launches the ppl picker then the code goes thru the config file to find out the claims provder/provders that are registered/listed here.The claims are
picked up and added to the SAML token

FillResolve : When some 1 checks the check box infront of the name that is there in the people picker
FillSearch  : when some types in the first letter in the searchbox of the claim(say m) and then hits search and the matching items come out.

CreateClaims() inbuilt method is used for the creation of claims .Helper methods should be used during coding.


Conclusions :
Provisioning permissions based on an attribute of the user, instead of on who the user is, opens many possibilities. It can mean, as it does in this scenario, that I do not care who you are. I do not care how you logged in. I do not care whether you are a Windows user
or a forms-based authentication user.

All I care about is who your favorite basketball team is.
Here is a classic problem from Microsoft Office SharePoint Server 2007 that still exists in SharePoint 2010—when I am at work, I log on to my SharePoint site by using my Windows credentials, Steve Peschka. But when I go home, I hit the site via our extra net and I must use forms-based authentication.

For our custom claims provider to support search, we must add support for the following properties and
methods of the SPClaimProvider class: SupportsSearch, SupportsResolve, FillSearch, FillResolve (the overload with SPClaim as an input parameter), FillSchema, and FillEntityTypes.


For Authnt/identity provider use the WIF classes.


=====================================================

User identity in Active Directory Domain Services (AD DS) is based on a user account. For successful authentication, the user provides the account name and proof of knowledge of the password. AD DS for account attributes and other information, such as group.

Claims-based identity is based on the user obtaining a security token that is digitally signed by a commonly trusted identity provider and contains a set of claims. Each claim represents a specific item of data about the user such as his or her name, group memberships, and role on the network Claims-based authentication in Windows is built on Windows Identity Foundation (WIF), which is a set of .NET Framework classes that is used to implement claims-based identity. Claims-based authentication relies on standards such as WS-Federation, WS-Trust, and protocols such as SAML.
If you select Claims-Based Authentication, SharePoint Server 2010 automatically changes all user accounts to claims identities, resulting in a claims token for each user. The claims token contains the claims pertaining to the user. Windows accounts are converted into Windows claims. Forms-based membership users are transformed into forms-based authentication claims. Claims that are included in SAML-based tokens can be used by SharePoint Server 2010. Additionally, SharePoint developers and administrators can augment user tokens with additional claims. For example, Windows user accounts and forms-based accounts can be augmented with additional claims that are used by SharePoint Server 2010.

Forms-based authentication is an identity management system that is based on ASP.NET membership and role provider authentication. In SharePoint Server 2010, forms-based authentication is available only when you use claims-based authentication. 


Secure Store Service(STS)
In Microsoft SharePoint Server 2010, the Secure Store Service replaces the single sign-on (SSO) feature of Microsoft Office SharePoint Server 2007. The Secure Store Service is a claims-aware authorization service that includes a secure database for storing credentials.
The Secure Store Service is an authorization service that runs on an application server. The Secure Store Service provides a database that is used to store credentials. These credentials usually consist of a user identity and password, but can also contain other fields that you define. For example, SharePoint Server 2010 can use the secure store database to store and retrieve credentials for access to external data sources. The Secure Store Service provides support for storing multiple sets of credentials for multiple back-end systems.

Usage :

Microsoft Business Connectivity Services    Can use Secure Store to map the user’s credentials to a set of credentials for an external system. You can either map each user’s credentials to a unique account on the external system or you can map a set of authenticated users to a single group account.

PerformancePoint Services    Requires Secure Store if you want to configure an unattended service account for data authentication.
Similarly it can be used for the same in the PowerPivot for SharePoint 2010,Excel Services,Visio Services

SharePoint 2010 Search

good course on Search :

http://msdn.microsoft.com/en-us/sp2010devtrainingcourse_extendingsharepointsearchlab_topic2

Scott Hillier speak on the search in SP 2010 is being noted below and I am a fan of this persons speaking

Managed Property

We create a managed property 'Avg Rating' and map it one to one with the crawled property OSS-AvgRating.
The Managed Property is kind of the HumanReadable property that u would like to map with the crawled property that is
fetched and indexed from the 3rd party data source.

Imp : A crawler crawls and fetches data from any ext sources in a raw form . Say crawled database gets info regarding geographies .Some call their geography USA,Some America,others come from Asia ,others from japan .
All of these can be grouped into one term called 'address' which can be in the managed database.So its a mapping from the crawled db to the managed db. 

Relevancy

When/while searching we have to increase relevancy
Ranking and Sorting :
Relevancy  is like a spice in the meal. u are nudging the item to be more relevant and then it will appear in the
search


Authoratative pages :

SSA and u can tell certain pages to be  authoritative page.So the docs will spear at the top
****** -- dint understand much

Custom Ranking models : new in SP 2010
Query independent element : no matter what the user type s (say) xml/doc elements are pushed to the top .
Q dependant element  : depending on the keyword that was typed.it rises to the top.

You have to enable the SpEnterprise SeachManagedproperty is explicitly use the managed property in the ranking model.
The next step is to create the ranking model which is nothing but an xml file as shown in the below screen shot . 

Here the 'body' is give '0' weight  in the query independent feature
BUt the q dependent feature is given the weight which is required here .
PID is the property id of the managed property that u care about.U can get the same using PowerShell

XML for Ranking Model





AFTER THATS DONE WE WILL HAVE to display the same using the searchCore Results webPart.SP has 6-7 OOB ranking models.There is a default ranking model that can be setup for this WEbP.The rest of the  6 of them are people search.We can get a list of SharePoint ranking models. Also we get the id related to each of those models .

CoreSearchResults Webp uses XSLT for the same .Value of the avg rating columns and    
Export the  webpart.Open the same and search for the 'DefaultrankingModel Property'change the value from and empty string to the GUID models that pwershell was used for installation, a few minutes back.

Search CR Webpart

Combination of PowerShell commands

Some results from the search :
suppose u type in
a* AverageRating>0

The search return the results after going through the ranking model and the index associated with the same.

Suppose u type in
AverageRating>0
Then the search only goes through the managed property database and not thru the ranking model/index etc.Its faster.
Reason : There is no value typed in  before the 'AverageRating' .Hence the search doesnt go deep .


Customizing Search center


In SP 2010 we can get involved in the search pipeline before the query is executed(before its fed into the search) and even after the query has been run(display of results using the XSLT).

All 'Site Content' , we can get the searachresults tab and the Searchtab. When we  edit the same we can see that they are tied to diff aspx pages .ie, Search Results.aspx and Search.aspx






The key new thing in SP 2010  is that we can inherit from the CorResultsWebpart and create a webpart based on the same.Inside the same we can create the object of the Query manager class and then create a query for the same.QM object allows u to insert/manipulate the pipeline before the query is executed.
Here in the picture is the 'Assigned To' managed property that we are targeting.




.Net asembly connector =  BCS model
It exposes the External system to crawling .
We can create custom connectors

BCS Allows    u to search external system.So in this example we search a external doc system for searching something . its external to SP so we will use BCS for the same .The solution here is that we  have the option of searching a doc and being able to open the doc.
We create an ECT -- is like a regular content type(doc/task CT).It represented fields from the external system and the operations that we can perform on that external doc system.So BCS creates an service class that is used to read the data that we want to.