Saturday, September 1, 2012

SharePoint 2010 PowerShell access error


Introduction:
We got the below error while access the SharePoint 2010 powershell and will see the solutions.
Error: “the local form is not accessible. cmdlets with FeatureDependecyId are registered.”
Solution1:
SQL Server Management studio connect to the SQL Server instance where the farm config database is stored. In the Security section give the user the following rights on the config database: SharePoint_Shell_Access
Solution2:
Use the following Powershell cmdlet to give this user the correct databases permissions, since Direct database changes are not supported: Add-SPShellAdmin
Summary:
“Add-SPShellAdmin” will be more simple and powerful and we have different option to access level also

Working With Form Based Authentication in SharePoint 2010


Introduction
In this article we will see how to enable Form Based Authentication (FBA) in a SharePoint 2010 environment.

Step 1
Form Based Authentication (FBA) requires understanding the Membership provider. Please check the following link for more details. We have a dependency with SQL Server to handle the SQL Membership provider.

Step 2
We need to enable Claim Based Authentication at the Web Application level. By default SharePoint 2010 sets the Classic (windows) Authentication. It's better to create a new Web Application with this option.
authenticationinsharePoint.jpg
AuthenticationinSharePoint
Once we have enabled it, we can see the Claims Authentication Types options as in the following:
authenticationtypeinsharepoint.jpg
Just specify the Membership provider name (AspNetSqlMembershipProvider) and we'll use the same name in the Config key also. For the signin page, we'll use the default option, if required we will change it to a custom page. We didn't any other option to create the site collection.
signinPageinsharepoint.jpg
Step 3
Our assumption is that we already configured the SQL membership DB using the command "aspnet_regsql". Check the following links for reference.

Step 4
We need to add our SQL membership DB connection string in the Central Admin web.config file.
C:\inetpub\wwwroot\wss\VirtualDirectories Ã CA site Ã web.config

Step 5
We need to repeat Step4 of the config changes for the site collection which we just created with Claim Based Authentication.

Step 6
Repeat the Step4 config changes for the SecurityTokenService web.config file also.
IIS path - SharePoint Web Services Ã SecurityTokenService
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\Root Ã web.config
In addition to this change, add the following key in membership. Note that the key name "AspNetSqlMembershipProvider" will be the same name as used in the site collection creation.
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true"requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"passwordStrengthRegularExpression=""/>
Step 7
After the config key changes, we try to create a new site in the same site collection, we will see the following message and it ensures us that our configurations are correct.
webconfiginsharepoint.jpg
Assuming we already created profiles with the name "venkat1" and while creating the new site collection, in the secondary site collection administrator, we didn't use a people picker control, just type your profile name and press Ctl+k, it will resolve automatically and in the tooltip we saw the profile come from "AspNetSqlMembershipProvider".
tooltipinsharepoint.jpg
Just browse to the newly created site collection URL, we will see the following login page:

selectauthenticationinsharepoint.jpg

If we choose "Forms Authentication", it will prompt for a user name and password as shown below:

Signinwarninginsharepoint.jpg
If the User Name and password are authenticated, we will login our site.
authentication1insharepoint.jpg

Summary
Form Based Authentication is one of the alternate methods of Windows Authentication. Still we have limitations like the profile created using the "sqlmembershipprovider" needs to have some level of access in the site, in the above sample we added the user as secondary site collection administrator, so that user can login using FBA and view the site.

Asset Bundling For .NET Web Apps


Introduction

In this article we will see how to use the CASSETTE framework and its implementation in ASP.NET.

About CASSETTE

Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS, Sass and HTML templates.

Step 1

Download the CASSETTE files from the following (or we can use the NUGET command to add the files to our project):

http://getcassette.net/download

Step 2

Once downloaded and the files referenced, it looks as in the following files:

Assetbundling.NETwebapps.jpg



We mainly used the "cassette" dll in this demo project and others are add by NUGET.

Step 3

Our package will add a configuration file as mentioned below in AppCode.

ConfigurationNETWebApps.jpg


Step 4

Add the required configuration details in that file, to control our CSS and JavaScript files.

ConfigurationdetailNETWebApps.jpg

We are not using any CSS files in the Demo project and we configured our scripts as the main/root folder for JavaScript.

Step 5

Add the script reference to the ASP.NET page, as a Casssette format; see:

ScriptReferenceASPNET.jpg


Add the RenderScripts() method for JavaScript load and RenderStyleSheet() method for CSS files; see:

RenderScriptmethodNETWebApps.jpg

Step 6

Run the page and you will see the result as in the following. To analyze the result we will add a simple ASP.NET and refer to the JavaScript.

ResultNETWebApps.jpg

We are able to see the JavaScript files, size and loading time.

JavaScriptNETWebApps.jpg

The preceding image is fiddler image for the same page, we will notice that every page refreshes and loads the scripts every time as a fresh request with the full file size.

Now let's see our actual implementation page result; see:
CassetteDemoPageNET.jpg

We will see the jQuery and prettyphoto files are loaded from the cache and its compressed. Let's see the fiddler image.
FiddlerImageNETWebApps.jpg
After the first time the scripts are loaded, it will load from the cache for any next page refresh.

CacheNETWebApps.jpg
In the fiddler, we won't find the script load for the subsequent page refreshes, because it's loading from the cache.

Summary

With a single change to Web.config,debug="false", Cassette switches into high-performance mode.

The CASSETTE bundle is flexible, extensible and optimized for developer happiness.

Asset Library Content Type Missing


Introduction

In this article we enable the SharePoint 2010 Asset Library Content Type. While attempting to create an Asset Library we are not able to find the "Asset Library" as shown below.

AstLBR1.jpg

If we check the site collection content type also, we are not able to find the "Asset Library" content types.

AstLBR2.jpg

Site collection -> Site Settings -> Site Content Types

Solution

Go the site collection feature link:

Site Collection Administration -> Features

Activate the following feature:

Once this feature is activated, we will have the following new content types in the site collection:

AstLBR3.jpg

Now we are able to see the "Asset Library" in the Create screen:

AstLBR4.jpg


Require.JS For Web Development: Part 2


Introduction

In this we will see some advanced features of Require JS and their implementation.

Config options

Let's start with various config options. We didn't used config file in the previous article.

What is in main.js?

A call to require() to load all the scripts you need and any initialization you want to do for the page. This example main.js script loads two plugins, jquery.alpha.js and jquery.beta.js (not the names of real plugins, just an example). The plugins should be in the same directory as require-jquery.js:

RqrJS1.jpg

Our config script will look like the preceding. Every parameter is optional and "baseUrl", "paths" are what we mainly used in this application.

Step 1

Add the script references as shown below in the Master page:

<script type="text/javascript" src="scripts/require.js"></script>
<script type="text/javascript" src="scripts/main.js"></script>
Now when we run the application we get the same results as in the previous article. Why do we want to use the Config option? Notice that we can shorten the JavaScript file names and control the script path also.

Now in the path section, we added two different versions of jQuery. Note that we didn't add the ".JS" file extension to the script names.
RqrJS2.jpg

In the Default page, we just added the following script. Two different versions of jQuery files will be handled in this script. One main advantage is that if we want to move to future versions of jQuery, we will simply change config file alone to upgrade the entire application.
RqrJS3.jpg

Shim

Shim is used to Configure the dependencies and exports for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value. Example:

RqrJS4.jpg

In this code we mentioned that "PrettyPhoto" is dependent on the "jQuery-1.6.1" version and every time the "jQuery-1.6.1" version is loaded before the "PrettyPhoto" loaded. We will check the order of the script as below.

RqrJS5.jpg

Module

Asynchronous Module Definitions are designed to load modular code asynchronously in the browser and server. It is actually a fork of the Common.js specification. Many script loaders have built their implementations around AMD, since it as the future of modular JavaScript development.

The Asynchronous Module Definition API specifies a mechanism for defining modules such that the module and its dependencies can be asynchronously loaded. Please check the following URL for more details about module.

http://requirejs.org/docs/whyamd.html

Created a simple module as mentioned below, just return some string data. We will notice that this as anonymous function, we didn't mention any names.
RqrJS6.jpg

Define another module with the name "another-message".
RqrJS7.jpg

For easy understanding these modules are kept as a separate js file and in the Main.jS (wherever required) we can refer to the modules as shown below:
RqrJS8.jpg

In this code we are calling the anonymous function module, passing jQuery and the anonymous function as the parameter and obtaining the results as shown below.
RqrJS9.jpg

We will combine one more module called "another-message" and the module code will be placed in a separate file.
RqrJS10.jpg

The output will combine the results of both modules and will see the order of the modules also.

RqrJS11.jpg

Summary

Using "Require JS" we will write clean code and resolve the dependence via creating the modules.

Call an ASP.NET C# Method (Web Method) Using JQuery

Introduction

In this article we will see how to call an ASP.NET C# method (Web Method) using jQuery.

Step 1

Add a jQuery reference to your project. 

Jquery1.jpg

Step 2

Add a web method in your page as mentioned below.

Jquery2.jpg

This method simply returns the Server Date time value as a string and the trick is it's a "Static Method", otherwise it won't work.

Step 3

We will use a jQuery "Ajax" method to call, page methods.

Jquery3.jpg

The URL value will be the page name/method name and the data will be the optional parameter to pass the value to the server.

Summary

Now we will call the C# methods and get the post back server data without a page refresh. This is one way to access the C# methods.

Basics of Require.JS For Web Development


Introduction

In this article we will see the basics of the "Required.JS" plugin and how to implement the various options of "Required.JS".

"RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino, Node and jQuery. Using a modular script loader like RequireJS will improve the speed and quality of your code."

Step 1

First let's understand the existing problem with a traditional approach and solution structure. We have an ASP.NET master page which has JavaScript references as mentioned below.
RQRJS1.jpg

For Demo purpose, I have created two pages using "prettyphoto" and "datapick" JavaScript files. Once we run the test pages, we will get the results as below.

PrettyPhoto sample page

RQRJS2.jpg

Calendar Page

RQRJS3.jpg

As we will see, the functionalities for the pages are working fine. But the problem is, in the calendar page I didn't use "PrettyPhoto.js" and in the PrettyPhoto page  didn't use "datepick.js". We have simple a page which doesn't use any JavaScripts, but all scripts are loaded because it's referenced in the Master page.

RQRJS4.jpg

Step 2

Download the sample code and the JavaScript file. Add the js files to the solution.

http://requirejs.org/docs/jquery.html

Comment the existing script references in the Master page and add the Require JS file. The data-main attribute on the script tag for require.js tells Require JS to load the scripts/main.js file. Require JS will load any dependency that is passed to require () without a ".js" file from the same directory as the one used for data-main.

RQRJS5.jpg

In this article we didn't used the main.jS file. Now in the default page we removed the unnecessary JavaScript files that were loaded.

RQRJS6.jpg

In the calendar page, just change the script as mentioned below to load only the required "datapick.js" file.

RQRJS7.jpg

In the calendar page we will see that only the Require JS, main.js and datepick.js files are loaded.

RQRJS8.jpg

In the Prettyphoto page the script to load only the required "PrettyPhtoto.JS" was also changed.

RQRJS9.jpg

RQRJS10.jpg

Summary

Using Require.JS, we will resolve the JavaScript dependency and improve the performance.