Thursday, July 25, 2013

Convert existing SharePoint Web Application from Classic Mode Authentication to Claims based Authentication

If you want to use FBA (Forms Based Authentication) with SharePoint you can, but you will need for the web application to be setup in Claims based Authentication instead of Classic Mode Authentication. One option would be to delete the application and re-create it using Claims based Authentication. While technically possible, it is a lot of work and not necessary. Instead, try using Powershell to solve this problem in seconds. Try the following:
  1. Open SharePoint Management Shell by going to Start Menu | All Programs | Microsoft SharePoint 2010 Products. Now right-click SharePoint 2010 Management Shell and choose Run as administrator.
  2. Now go the following Powershell commands:

    PS> $app = Get-SPWebApplication "http://yourSpHost:7777"
    PS> $app.UseClaimsAuthentication = "True"

    PS> $app.Update()
  3. To verify the change: Go to Central Administration | Manage web applications, and select the application you modified.
  4. Click the Authentication Providers button in the Web Applications ribbon. It will now show Claims Based Authentication.
 Troubleshooting:
NOTE: if you get the error: "The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered." try some of my fixes outlined here

Resolving: The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

If you try to run something like Get-SPWebApplication http://yourSpHere:1234 you may get the error:

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.


Things to try.

1. Make sure you run the command as Administrator. For example, Go to Start Menu | All Programs | Microsoft SharePoint 2010 Products. Now right-click SharePoint 2010 Management Shell and choose Run as administrator.

2. If that doesn't work then it is likely you don't have access to the SharePoint configuration database. On solution would be to grant your users access to the configuration database, but that probably is not the best plan.

3. A better option is use a user that does have rights to the configuration database. This is often a SharePoint service account. If that service account has RDP access you one of your SharePoint front end servers then login as that service account and execute the command. If you want to be able to execute it with your specific account, then we need to do some more things. You can do the same thing as #1 to bring up the SharePoint 2010 Management Shell, and then execute

powershell prompt>Add-SPShellAdmin -UserName yourdomain\yourusername

This should make it so your specific user can now do #1.

If the SharePoint service account does NOT have RDP access then things are a bit trickier. In that case, follow these instructions:
  1. RDP to the SharePoint server using an account (usually in the adminstrators group in Windows) that can execute RunAs command.
  2. Go to Start Menu | All Programs | Accessories. Then righ-click on the Command Prompt item and select Run as administrator.
  3. Now we need to open the PowerShell prompt as the SharePoint service account. To do this, do the following command:

    cmd promopt>runas /user:yourdomain\yourusername C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  4. Type whoami at the prompt to verify that you are indeed the service account.
  5. At this point we have a standard Powershell prompt, but it doesn't know about SharePoint, so we need to add it. Use the following command to do so:

    powershell prompt>Add-PSSnapin Microsoft.SharePoint.Powershell
  6. Now you should be able to grant your specific user rights to use SharePoint powershell commandlets. To do so, use the following command:

    powershell prompt>Add-SPShellAdmin -UserName yourdomain\yourUserName
  7. Now you should be able to use method #1 with your specific user and not have to do all this fancy stuff everytime.

Wednesday, July 10, 2013

How to Center a DIV tag horizontally using CSS

I miss the days of using the CENTER tag. Now it seems it is not really a good idea to use the CENTER tag. It is recommended that CSS be used instead. It seems that it is a bit more difficult to do with CSS.
In this example, my DIV only contains text, but it could contain anything. If it was just text, text-align:center could be used, but to center a div tag and its contents it takes a bit more.

First thing we need to do is give the DIV a width and then it can be centered. Here is an example of how to center a DIV that is 400px wide.


<div style="width:400px; display:block; margin-left:auto; margin-right:auto>">
some stuff here
</div>


You can also create a CSS class and reference it, but I have put the style inline for simplicity, but probably not a good for maintainability.

Thankfully, this is pretty simple once you know what to do.