Tuesday, November 8, 2011

Customizing the Login Page in SharePoint 2007


Microsoft SharePoint 2007 gives you the option of using forms authentication, but the out-of-the-box forms-based login experience is fairly bland. It’s not bad if you’re doing something for internal use, but if you’re doing something for internal use then you’re probably using Windows authentication. Forms authentication is normally found on external or customer facing sites where corporate branding is a big deal, and master pages play a major role in presenting a consistent look and feel throughout a SharePoint site. But when you apply a master page to a publishing site, or edit the default.master in a team site, you’ll quickly find out that it doesn’t alter the look and feel of the login page. In this article, we’ll take a look at why that is and what you need to do to get your login page in line with your corporate brand.
If you’re wanting to know how to enable forms authentication in SharePoint 2007, check out this article: Configuring Forms Authentication in SharePoint 2007.

Where does the login.aspx page reside?

When you try to view a protected page in a forms authenticated site, SharePoint redirects you to the login page (Figure 01). At the login screen, take a good look at the URL in your browser notice that the login.aspx page is in the _layouts folder. If you browse to the directory that houses your SharePoint application, you’ll quickly notice that there’s no _layouts folder in the directory itself. This isn’t a shocking revelation to most because a lot of the pages you see in SharePoint don’t actually exist on the file system. But if you open the Internet Information Services (IIS) manager snap-in and navigate to your SharePoint site, you’ll find that the _layouts folder is actually a virtual directory that points to the following real-life directory on your server (assuming you installed to the default location):
C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\12\template\layouts
The layouts folder contains application and system pages used by all the SharePoint sites on your server. Upload a new document to a site you’ll end up on the upload.aspx page from the layouts folder. View the people who have access to the site you’ll be on the people.aspx page. And if you’re trying to login, you’ll be hitting the login.aspx page. There are 400 pages in the directory, each of which has its own specific point and purpose, so it’s impossible to go into detail on each page. But they are all in there.
Figure 1 – the login.aspx page

Global consequences of changing files in the _layouts folder

Armed with the location of the application system pages in SharePoint, you may be tempted fire up an editor and start hacking away at them, but you should probably know what you’re getting yourself into before going down that path. Remember how the _layouts folder in your SharePoint site is a virtual directory that points to C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\12\template\layouts? Well, all of the SharePoint sites on your server are setup in exactly the same way. That means when you change something in the _layouts folder for one site, you’re changing it for every single SharePoint site on your server. It also means that you’re editing the only version of the file on your system, so you’d better make a backup of the folder content. Otherwise you’ll have to reinstall SharePoint to get those files back into working order if you have a nasty mishap.

Creating a site-specific _layouts virtual directory

Depending on your situation, applying changes to all of the sites on your server may or may not be a bad thing. If all of the sites on your server need the exact same branding, layout, and functionality, then go ahead and make the change directly in the standard layout folder (after backing it up). But you may just as well find yourself in a situation where each site needs to be different, so applying a sweeping change to all the sites won’t work. What do you do when you find yourself in that situation? You make a copy of the shared layouts folder specifically for your site, and make the changes in that site-specific copy. To do this, take the following actions
  1. Navigate to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\12\template\ folder
  2. Select the layouts folder and copy it
  3. Navigate to the root directory of your SharePoint site
  4. Paste a copy of the layouts folder in your SharePoint directory
  5. Rename the layouts folder _layouts
  6. Open the IIS manager snap-in
  7. Expand your SharePoint site’s website entry
  8. Right click on the _layouts virtual directory (you may also see a non-virtual _layouts folder) and select Properties from the context menu
  9. On the virtual directory tab, click the Browse button next to the Local Path textbox to display the directory selection dialog
  10. Navigate to the _layouts folder you just created in your SharePoint site, select it, then click OK
  11. Click OK to apply the change to the _layouts virtual directory
Now you can make changes in the _layouts folder for your SharePoint site without it affecting other sites on your server.
Warning: some operations in SharePoint Central Administrator, like extending a site or changing the authentication type for a zone, can “reset” the _layouts virtual directory in your SharePoint sites so they point back to C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\12\template\layouts. When this occurs, just go back into the IIS manager snap-in and point the virtual directory back over at the _layouts folder copy for your site.

Login.aspx and its Master Page

When you open the login.aspx page you’ll quickly discover it’s a content page containing markup for a title, layout table, username textbox, password textbox, a login button, a “remember me” checkbox, and a few content controls to helpful text labels next to some of the fields. Just enough markup for a non-descript login form, but certainly not enough to make the unsightly bluish surroundings on the Standard SharePoint login page (see Figure 1 again). The login page relies on the simple.master page in the _layouts folder to define most of the look and feel you see around the page (see Figure 2). Following is the Page directive found at the top of the login.aspx page which shows the association of the simple.master with the page:

<%@ Page Language="C#"    Inherits="Microsoft.SharePoint.ApplicationPages.LoginPage"    MasterPageFile="~/_layouts/simple.master"%>
When you’re considering changing the look and feel of the login form, you need to determine exactly what you’re trying to accomplish. If you want to change the branding surrounding the form itself, then you need to edit the simple.master page. If you want to change the login form itself, by rearranging controls, adding additional help text, graphics, etc, then you need to edit the login.aspx page.


Figure 2 – simple.master from the layouts folder

Editing the simple.master page

Like most master pages, the simple.master controls the look and feel or more than just a single page. In fact, it controls the look and feel of seven pages in the _layouts folder:

Page Name Description
AccessDenied.aspx Displays a notice that you have been denied access to the requested resource. Shows the name of the currently logged-in user and a link to sign-in as a different user.
Confirmation.aspx Displays a message indicating that the requested operation succeeded.
Error.aspx Displays a message indicating that an error has occurred. May also display additional stack trace information if the site has been configured to do so.
Login.aspx Display a login page allowing users to enter forms authentication credentials.
ReqAcc.aspx Displays a notice that you have been denied access to the requested resource.
Signout.aspx Responsible for logging a user out of the site.
Webdeleted.aspx Displays a message indicating the web site has been deleted.

People visiting your forms authenticated SharePoint site will run into a couple of these pages on a regular basis, so you’ll definitely want to include the simple.master in any branding efforts you undertake for your SharePoint site. But with seven different pages relying on the simple.master page, the question is what can you change on the simple.master page and what do you have to leave? Master pages contain ContentPlaceHolders controls that identify sections of the page into which content may be injected by a content page. Content pages contain Content controls that refer to the ContentPlaceHolder controls in the master. If a content page refers to a ContentPlaceHolder in the master, but you’ve removed that ContentPlaceHolder, an error occurs. So, the key to modifying a master page is to NOT remove any required ContentPlaceHolder controls.
Determinging exactly which ContentPlaceHolder controls are required in a master page can be fairly arduous because some of ContentPlaceHolders may be required by one page but not another. For example, the simple.master page contains a ContentPlaceHolder controls named PlaceHolderPageImage. If you remove it from the simple.master, the login.aspx page loads without a problem because the login.aspx page doesn’t reference the control. But you do get an error when you hit the AccessDenied.aspx page because it uses the PlaceHolderPageImage to insert a little icon on the page. Since the simple.master only controls the look and feel of seven pages, it doesn’t take too much time to check each page to see if you removed a required control. With other master pages you’re not so lucky. The application.master, for example, controls the look and feel of more than 200 pages. And that’s just too much to test.
One way to avoid the headache of accidentally removing required controls is to leave them on the page, but hide them. The process looks something like this:

  1. Open your master page file
  2. At the bottom of the page, add a hidden panel using the following code:
        <asp:Panel runat="server" visible="false">
        </asp:Panel>
  3. Look through the markup of your content page and locate any ContentPlaceHolder controls (or any other server controls for that matter) on the master page
  4. When you find a ContentPlaceHolder control (or a server control) cut and paste it into that hidden panel
When you finish, you’ll have a master page whose server controls are entirely contained in a hidden panel. View any page that references that master, and you’ll see that the page renders without any errors because all of controls that were originally there are still there, they’re just hidden. Of course, it also renders without any content because the hidden panel is hiding everything, but you’ll take care of that next. Now you can begin altering the look and feel of the master page by adding in the branding elements for your corporate image. As you do so, you can begin adding back in any ContentPlaceHolders and server controls that you want in the final master page.
If you’re curious, the following ContentPlaceHolders are required in the simple.master:

  • PlaceHolderAdditionalPageHead
  • PlaceHolderPageTitle
  • PlaceHolderSiteName
  • PlaceHolderTopNavBar
  • PlaceHolderTitleBreadcrumb
  • PlaceHolderPageImage
  • PlaceHolderPageTitleInTitleArea
  • PlaceHolderMain
  • PlaceHolderPageDescription
You’ll also probably want to keep the ScriptLinkControl named ScriptLink1 as well, because it contains important JavaScript includes.

Editing the login page

Editing a content page is a much less perilous task than changing a master page because any bugs you introduce are localized to the page itself. You can keep a copy of the page up in your browser and refresh the screen when you make a change to see if it breaks. Like the master page, the biggest thing to remember on a content page is that the class which controls the page is looking for specific page elements. If it tries to find a page element and it’s not there, the page throws an error and won’t render. If you do not want an element to display on the screen, you can place that control in a hidden Panel control to hide it from view without breaking the code that controls the page.
Most of the changes you’ll be making in content pages are going to be cosmetic, and will likely revolve around adding some additional content here and there and changing the layout of elements inside the page. Understand, however, that all of these SharePoint pages are built using ASP.NET technology. As such, these pages can be altered any way that you could normally alter an ASP.NET page, allowing you to do some really heavy renovations if you so choose. For example, take the login.aspx page. Here’s the Page directive found in login.aspx:

    <%@ Page Language="C#"
         Inherits
="Microsoft.SharePoint.ApplicationPages.LoginPage"
        
MasterPageFile="~/_layouts/simple.master" %>
Notice that the page references the simple.master as its master page and inherits its functionality from Microsoft.SharePoint.ApplicationPages.LoginPage class. If you don’t want the login.aspx page to use a master page, you can remove the MasterPageFile element in the Page directive and place all of the branding markup directly in the login.aspx page itself. I don’t recommend the approach, but you can do it. Or what if you don’t like the way the Microsoft.SharePoint.ApplicationPages.LoginPage class handles the page? You can remove the element to remove the page logic entirely, or point it at a different class. If you do remove the Inherits element, you can still write your own custom code for the page by adding server-side script directly in the login.aspx page. I put the following code in my login.aspx page and it works just fine (and it actually logs you into the site too!)
    <%@ Page Language="C#" %>
    <script runat="server">        protected override void OnLoad(EventArgs e)        {
            Response.Write("This is from the onload event");
            base.OnLoad(e);
        }    </script>    <html>
         
<body>              <form runat="server">                  <asp:login id="login" runat="server" />              </form>          </body>    </html>
Is it a good idea to get rid of the master page and the controlling class for a SharePoint page? Absolutely not! But it does show you the flexibility you have in editing pages.

Conclusion

You’ve seen where you can find the SharePoint login page and the master page that controls its look and feel. You’ve learned the global consequences of editing pages in the _layouts folder, and how to avoid those consequences if you need changes to apply to a single site on your server. You’ve got some good guidelines for editing master pages. And you know that you can do just about anything you want to a content page. So you should have a sporting chance at changing just about anything you want on the login page or any other SharePoint application page.

Wednesday, September 14, 2011

Configuring My Site in SharePoint 2010

SharePoint My Sites are commonly referred to as “Facebook for the enterprise” and are personal site collections providing each user with the ability to store private and public information such as documents, pictures, status updates, etc easily and efficiently.  My Sites in SharePoint 2010 takes social enterprise computing to the next level and builds upon what we have come to love in previous versions.  Microsoft saw the need to continue to invest and enhance SharePoint’s social networking capabilities, and as web 2.0 technologies continue to sprawl all over the world wide web, Microsoft have again successfully set the bench mark in the enterprise by introducing an array of social computing features to enhance end user collaboration in SharePoint 2010.
In my last article I introduced and configured our first service application for our SharePoint 2010 deployment, User Profiles, which provided us with a central location for storing user details that will later be imported from a content source such as Active Directory.  Today we will continue our journey to plan and configure User’s My Sites in SharePoint 2010.
Prerequisites
This article is the 5th in my series on deploying SharePoint 2010 for the enterprise, so if you have missed the first 4, you can easily catch-up via the links below;
  1. Installing SharePoint 2010 using Least Privilege Service Accounts
  2. Configuring incoming email in SharePoint 2010 with Exchange 2010
  3. Configuring outgoing email in SharePoint 2010 with Exchange 2010
  4. Configuring the User Profile Service in SharePoint 2010
Create the My Site Web Application
We begin by first creating a Web Application that will eventually house our My Site Host and subsequent site collections.
Navigate to Central Administration / Application Management / Web Applications
Click New
image thumb Configuring My Site in SharePoint 2010
Authentication: Select either Claims or Classic depending on your requirements.  I will select “Classic”
IIS Web Site: Create a new IIS web site (enter your details as per your requirements)
image thumb1 Configuring My Site in SharePoint 2010
Authentication Provider: Select your preferred provider based on your requirements.
Public URL: Specify the URL that users will type to access their My Sites.
image thumb2 Configuring My Site in SharePoint 2010
Application Pool: Create a new application pool and give it a descriptive name
As we have been utilizing the least privilege model whilst configuring our SharePoint farm in this series, we will click on Register a new managed account and enter the details for our My Site Application Pool Identity.  Note: This account will be required to be provisioned in Active Directory before you can proceed. e.g. In my example I have created an account called DOMAIN\sp_mysite.
image thumb3 Configuring My Site in SharePoint 2010
Click OK
image thumb4 Configuring My Site in SharePoint 2010
Database Name and Authentication: Specify your Database server and Database name.
Failover Server: Specify your failover server if you are utilising SQL Server database mirroring.
image thumb5 Configuring My Site in SharePoint 2010
Click OK
You should receive the below confirmation that the Web Application has been successfully created.
image thumb6 Configuring My Site in SharePoint 2010
Click on our newly created “SharePoint – My Site” Web Application and click on General Settings.  Proceed to fill out your Web Application specific settings such as the Default Time Zone etc.
image thumb7 Configuring My Site in SharePoint 2010
Create the My Site Host Site Collection
Now that we have successfully created our My Site Web Application, we can now proceed to create our My Site Host Site Collection.  This will be the top level site that will house our individual user’s site collections.
Navigate to Central Administration / Application Management / Create site collections.
Ensure that the recently created My Site Web Application is selected, enter in a Title and click select the My Site Host Template located under the Enterprise Tab.  Lastly, specify your site collection administrators and click OK.
image thumb8 Configuring My Site in SharePoint 2010
You should then receive confirmation that the top level My Site Host has been successfully created.
image thumb9 Configuring My Site in SharePoint 2010
Setup My Sites
Now that we have successfully provisioned our My Site Web Application and Top Level Site Collection that will host our My Sites, we can continue to configure our My Site Settings.
Navigate to Central Administration / Application Management / Manage service applications.
Click on User Profiles.
Click on Setup My Sites located under My Site Settings.
image thumb10 Configuring My Site in SharePoint 2010
Enter the details of your Preferred Search Center if you have one setup already.
Enter the URL of your My Site Host that we have just created in the previous step and the personal site location.
image thumb11 Configuring My Site in SharePoint 2010
Finally, select your Site Naming format, configure your Language Options, Permissions and My Site Email Notifications.
image thumb12 Configuring My Site in SharePoint 2010
Click OK.
Add our Managed Path
Because we have specified “personal” as our Personal Site Location, we will need to define our managed path against our My Site Web Application.
Navigate to Central Administration / Application Management / Manage Web Applications.
Click on your My Site Web Application and click on Managed Paths from the Ribbon.
image thumb13 Configuring My Site in SharePoint 2010
Add “personal” as a Wildcard inclusion, click Add Path and click OK
image thumb14 Configuring My Site in SharePoint 2010
Enable Self-Service Creation
Our last configuration step provides our users with the privilege to provision their own My Site’s by enabling the Self-Service Creation.
Navigate back to Central Administration / Application Management / Manage Web Applications.
Click on your My Site Web Application and click on Self-Service Site Creation.
image thumb15 Configuring My Site in SharePoint 2010
Select On and click OK.
image thumb16 Configuring My Site in SharePoint 2010
If I now browse to my My Site URL I will be presented with the following “What’s New” Page.
image thumb17 Configuring My Site in SharePoint 2010
It is only until I click on “My Content”, that SharePoint will proceed to create my personal site as per SharePoint 2007.
image thumb18 Configuring My Site in SharePoint 2010
My Content
image thumb19 Configuring My Site in SharePoint 2010
As you can see, we have now successfully completed our setup of a My Site Host which will house our user’s My Sites.

Console Application error: The Web Application at could not be found

When we create the Console applications in SharePoint 2010 Server,  their application kept on getting the following error, when trying to create a new instance of SPSite:
System.IO.FileNotFoundException: “The Web application at http://sharepointsite could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.”
image
To fix this in SharePoint 2010, there are a few things that should be done:
1. Under Project Properties –> Application, Ensure that the target framework to be compiled against is .NET Framework 3.5

image

2. Under Project Properties –> Build, Ensure that the platform target is set to x64

image

3. Ensure that the SPSite URL you are trying to open is in your Central Admin –> Web Application alternate access mappings

SharePoint 2010 Metadata and Taxonomy Management

I finally got around to reading the preliminary SharePoint 2010 taxonomy and metadata info on MSDN. As most of you know, MOSS 2007 had some serious challenges in this regard (e.g., no hierarchical metadata, no sharing controlled vocabularies across site collections, etc.) — and they caused information architects like me much consternation.
It would appear that SharePoint 2010 includes many new features under the umbrella of Enterprise Metadata Management, and they seem to have addressed some key issues. Here are the highlights.

1. Terms & Keywords

SharePoint 2010 has a few types of vocabularies with different levels of control:
Terms: Basic construct — a word or phrase that can be associated with content. A term can become a managed term or a managed keyword.
Managed Terms: A controlled term that can only be created by those with appropriate permissions. Term sets (think of them as taxonomy facets) are collections of related terms that can be hierarchically structured.
Managed Keywords: User-generated keywords (aka tags) kept in a non-hierarchical list called the keyword set.
What's nice is that you can easily turn a managed keyword into a managed term, which essentially sets up SharePoint 2010 as a decent platform to blend taxonomy and folksonomy approaches (more on this later).


2. Managed metadata & the Term Store

Once you have managed terms in place, you can create a new column type called "managed metadata". This column type is like the 2007 lookup, but points to the managed term sets instead of lists.
One of the biggest limitations of MOSS 2007 was the site collection boundary: lists were specific to a site collection, so in order to share metadata and taxonomy across multiple collections, you had to essentially reproduce the same lists in each collection.
Managed term sets (and managed keywords) now live in what's called the Term Store Management Tool — a centralized database that allows term sets to be shared across a farm.
sp2010-metadata-20091112-01.png
SharePoint 2010 — Centralized Metadata Repository. Image courtesy of EndUserSharePoint.com


3. Taxonomy & Metadata Management

Within the Term Store, there are some metadata and taxonomy management functions enabled, though the documentation is not clear on how many of them are achieved.
Feature Comment
Create or delete term sets Term sets can also be thought of as facets
Add, modify or delete terms It is unclear however how modifications and deletions are propagated throughout content that is already tagged - this is a big problem in 2007, as changes are not reflected in tagged content
Arrange terms in hierarchies It would appear that this uses a drag & drop mechanism
Define synonyms Unclear as to how this works and whether it is used in the search thesaurus
Import terms Via a .CSV file
Promote managed keywords into managed terms Great news for those of us who want to use tags as a source of candidate terms for the taxonomy
Create multi-lingual     taxonomies Unclear if this is at the term level or you have to create language-specific versions of each term set… likely the latter
My biggest concern is the whole question of integrity and change propagation, but overall this is a huge leap forward from 2007 where there was no taxonomy management to speak of. This is actually more functionality than I've seen in many very expensive CM suites, so right now on the surface, I'm rather pleased with this set of features.

Using Managed Metadata in SharePoint 2010


Managed Metadata is a really cool new feature in SharePoint 2010. You can centrally define metadata which can be used across Site Collections. This Term Sets can be statically defined by a Group Manager or dynamically extended by your users. I will show you how to create such an Group and Term Set and how to include it in a Document Library.

First of all you have to start the required Web Service. So within the Central Administration click on the link “Manage services on server“.


There you’ll find the “Managed Metadata Web Service“. Use the “Start“-Link on the right side to start it.



Now we have to create a service application which handles the managed metadata. In Central Admin within the Application Management use the Manage service applications link to get an overview of the currently created service applications.
Side Note: Service Applications are the follower of the Shared Service Provider (SSP) in SharePoint 2007.


Use the New Button at the Service Applications Ribbon and choose “Managed Metadata Service“.



Enter your desired options. The options are self-explaining.
After the creation process you find your new service application in the list. Click on the Name of the Service Application or highlight it and use the Manage Button within the Service Applications Ribbon to enter the Term Store Management Tool.



First of all we have to create a new group for our Term Sets. When moving the pointer over the name of your Service Application (in my case its “Managed Metadata Service SA”) a little arrow appears. After clicking on this arrow the below showed menu appears. Now use the New Group link and enter the name of the group.




After entering the name you can hit Enter and the properties of this group are displayed. I think the options here are self-explaining as well.


Now create a Term Set which will hold our Terms (Metadata). The Term Set is the part which will be used in a column. Basically it’s the same process as the creation of the group. Move the pointer over your group, click on the small arrow and choose New Term Set. It’s also possible to import a CSV-File.



After hitting Enter again you’ll find yourself in the properties of this new Term Set. Especially the “Submission Policy” setting is interesting. If you want a dynamic list (which is extendable by your users) you have to change this option to Open.



Once again, we have to use our little arrow to create new Term’s inside this Term Set.


You can define multiple synonyms for each term. If this synonym is typed by one of your users the right Term will be displayed as suggestion.


So, after all you Term Set was created we should also use it ;)
Create a new column in a List or Document Library within your Site Collection.






Enter a Column name and choose “Managed Metadata” as information type.


Puhuu, what’s that? ;) I’m not sure if it’s just a bug within the RC1-Edition, but we have to enable the Term Navigation through PowerShell. Yep, the required feature isn’t available through the “Site Feature” list inside the “Site Settings”.



Start PowerShell and add the SharePoint SnapIn so the required cmdlets are available.
Get-PSSnapin –RegisteredDisplays all PowerShell-Snapins which are available on your machine
Add-PSSnapin Microsoft.SharePoint.PowershellAdds the SharePoint-Snapin to this PowerShell session



If you don’t trust me that you have to enable the feature you can check it ;)
Get-SPFeature –Site <URL to your Site Collection>Displays a list of all already enabled Site Features
Enable-SPFeature -Identity 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -Url <URL to your Site Collection>Enables the “TaxonomyFieldAdded” feature for the specified Site Collection. This one is required for the Taxonomy Browser.
Get-SPFeature | where {$_.displayname –like “*tax*”}
A list of all available features on this Farm are displayed which have tax in their name. This would be an option to get the ID of the feature. The other option would be to try to create a column while this feature is disabled. You will receive the error: “The Taxonomy feature (Feature ID “73EF14B1-13A9-416b-A9B5-ECECA2B0604C”) has not been activated.<br>A term set or anchor point was not selected”.





So, feature is activated and we’re ready to use it. Refresh the page. Now your Managed Metadata Service Application with the Group and Term Set is display.


If you want the Term Set to be dynamically extendable set “Allow ‘Fill-in’ choises” to “Yes“.
After using the “OK-Button” to create the new column just upload a document. Our column is displayed and while you’re typing a value relevant suggestions are displayed. You can also click on this tiny cards (or whatever it should be) on the right side of the input box to display all available Terms. This is also the required step if you want to add a new Term.



Use the “Add New Item” to, what a surprise, add a new term ;)


That’s it ;) You can also try to add a column which is using your Term Set on another Document Library and even on a DocLib within another Site Collection and you’ll find all Terms.
There are still some open questions for me where I have to play more with this feature. Especially with permission on the Term Sets and Groups. But all Managed Metadata would solve a lot of troubles we all had with SharePoint 2007.
In my opinion it’s just important to clearly understand the impact of Managed Metadata and to plan it carefully. It’s like with Content Types => A good concept is everything ;)