Monday 13 April 2015

ASP.NET Session State in SharePoint Farm



When third party controls/custom solutions need Session State in SharePoint Farm, how to enable it?



ASP.NET Session state is disabled by default in SharePoint 2010 installation. However, there may be need in custom solutions, web parts & third party tools like Telerik reports on top of SharePoint 2010 framework where persisting information per user session is required. This is a case study we have done for our project referring below mentioned blog.



ASP.NET Session State implementation in SharePoint?


As many of you are aware, ASP.NET allows persisting session states in three different ways.

  • On server memory as a InProc
  • On SQL Server to persist session in database
  • On Session State Server to persist session on dedicated server memory.

Both SQL Server Session State Server would support server farm environment.
Since SharePoint is the multi-server farm environment based on ASP.NET framework, by default, it can be enabled to use SQL Server and SqlSessionStateStore provider to persist session state using ASP.NET Session State Service Application.

How do I enable ASP.NET Session State in SharePoint?

ASP.NET Session state is available to the SharePoint environment by enabling “SharePoint Server ASP.NET Session State Service” service application on the SharePoint farm. You can’t enable this service application using central administration browser interface. You must enable it using PowerShell command.

Step 1: Enable ASP.NET Session State Service

To enable ASP.NET session state, log on the Central Admin Server using Farm Admin Account

Run PowerShell command

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Enable-SPSessionStateService –DefaultProvision


Creates service application with default state. By default, this will create service application database with “SessionStateService_<GUID>”, on the same database server where farm configuration database is located using windows credentials of the logged in user.

Run PowerShell command

“Enable-SPSessionStateService -DatabaseServer YourDBServerName -DatabaseName YourDBName”

Creates service application with specific database name on non-SharePoint configuration database server. By enabling Session State Service on your farm, it would create database on specified server – SessionStateService_<GUID>

It would create SharePoint Server ASP.NET Session State Service in Manage Service Applications

It would add module in all web applications on farm

<add name=”Session” type=”System.Web.SessionState.SessionStateModule” />

It would add sessionstate entry in all web applications on farm
<sessionState mode=”SQLServer” timeout=”60″ allowCustomSqlDatabase=”true” sqlConnectionString=”Data Source=SP2010VM;Initial Catalog=SessionStateService_1079ab25364440b0b38b15ad2392b6d0;Integrated Security=True;Enlist=False;Connect Timeout=15″ />

Step 2: Activate ASP.NET Session State on SharePoint Web Application
By enabling ASP.NET session state service in the SharePoint farm, every SharePoint web application in the farm ready to use ASP.NET session framework. To ensure SharePoint web application gets activated to persist ASP.NET sessions, you have to manually update Web.Config file for the specific SharePoint web application on all servers in the farm.  


<pages enableSessionState=”true”


How would you use ASP.NET Session State Service in Code?

You can access ASP.NET session state object using HTTPConext.Current.Session and use the ASP.NET session state same as typicallyASP.NET Session Management. Here is the sample code which would create newASP.NET session object called “Just4sharing_VWebPart1session”, if it doesn’t exists. Let us create a Visual web part in SharePoint and add code to add session.

Step 1: Create a new SharePoint 2013 web part project


Step 2: In page load add code to save session key as seen in the code.


Step 3: Deploy solution and add web part to your site

Step 4: Save and refresh the page


After above code runs, this is what you would see in the ASP.NET Session State Service Application database.

By default, it would create session for 60 minutes. If you want to increase or decrease session expiration, you have to pass “SessionTimeout” parameter while creating ASP.NET Session State Service using Enable-SPSessionStateService command.

Happy coding!

Sunday 12 April 2015

useful SharePoint tools/add-ins for better development experience.

These are some of the useful SharePoint tools/add-ins we use in our day to day tasks for better development experience.

Tools/add-ins
Description/purpose/link
SharePoint Designer
Using SharePoint Designer, you can rapidly create SharePoint solutions in response to business needs.
Obfuscator
Reverse engineering managed code
CKSDev
Add-on for Visual Studio that adds shortcuts and templates for common SharePoint scenarios.
Productivity Power Tools

A set of extensions to Visual Studio Professional (and above) which improves developer productivity.

AnkhSVN
Source control client for SVN (including #define).
TortoiseSVN
Source control client for SVN (including #define - note that a license for this may be included in the #define license.)
StyleCop
Used for analyzing code based on predefined rules.
Notepad++
Text editor that can be used as a complement to the editor in Visual Studio and replaces Notepad.
http://notepad-plus-plus.org/
.NET Reflector
Used for inspecting compiled code, for example the SharePoint assemblies to really understand how things work.
ILSpy
Used for inspecting compiled code, for example the SharePoint assemblies to really understand how things work.
ULS Viewer
Free tool to monitor and read the logs produced by SharePoint.
http://bit.ly/1akVR2A
ULSViewer
http://bit.ly/1pbYGbZ - updated version from MS
http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-48-65-metablogapi/ULS1_5F00_7B4EB960.png
SharePoint ULS Viewer
ULS Viewer
SoapUI
Tool for testing and inspecting web services
testing-anyone
SharePoint Log Viewer
The most advanced and easy to use viewer of MOSS/WSS ULS logs.
SharePoint Log Viewer
Event Viewer
Helps you to see application and system logs
%windir%\system32\eventvwr.msc /s
WcfTestClient
Tool for testing and inspecting web services. Included in VS2010.
…\Common7\IDE\WcfTestClient.exe
Fiddler
Tool that acts as a proxy and makes it possible to inspect web requests/responses of different kind. Can also be used for monitor calls done by the w3wp process by modifying Web.Config.
Firefox + Firebug
Good complement to Internet Explorer and Developer Tool bar that has advantages in some cases.
Beyond Compare
Tool for comparing files.
WinMerge
WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
File Comparison
GIMP
"GNU Image Manipulation Program". Can be used for simpler image manipulation but does not replace Adobe Photoshop for more advanced scenarios.
Paint.NET
Can be used for simpler image manipulation but does not replace Adobe Photoshop for more advanced scenarios.
SharePoint Manager
Inspection and manipulation of a SharePoint environment. Note that there are different versions for 2007 and 2010. Must be started under administration privileges.
03170127_small.jpg
Sandcastle
Compiles HTML help files from the XML documentation.
SharePoint Dispose Checker
Utility for double-checking if SharePoint objects are properly disposed
PowerGUI
GUI and script editor for PowerShell
GUID generators
Online GUID generators
Use "[Guid]::NewGuid()" in PowerShell.
ReSharper
Refactoring utility
SharePoint Content Deployment Wizard
This tool is for moving content in *SharePoint 2007/2010/2013* - within an environment (or across similar environments). 
CDW_ExportSelect.jpg
SharePoint SUSHI
SharePoint SUSHI is a powerful, user-friendly utility enabling you to accomplish common administrative tasks. You can think of SUSHI as a Swiss army knife for SharePoint.
SUSHI = SharePoint Utility with a Smart, Helpful Interface
sushi_homepage4.png
CAML Query Builder
CAML (Collaborative Application Markup Language) is an XML-based query language that helps you querying lists and libraries in SharePoint.
Unit Tests
NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 2.6, is the seventh major release of this xUnit based unit testing tool for Microsoft .NET. It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages. http://www.nunit.org
Typemock –
WcfTestClient
Site Property Bag Configuration Tool
SharePoint Property Bag offers developers to store configurations settings at different levels of the SharePoint hierarchy outside of the application itself.
pbs2010_0.png
Validate HTML and CSS using one or more of the following tools:
Visual Studio,

This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, MathML, etc.

Windows PowerShell for SharePoint Command Builder


Distributed Object Caching and BLOBS
Happy coding!