Wednesday, August 3, 2011

SharePoint 2010 Turn on Developer Dashboard

One of the new feature in SharePoint 2010 is Developer dashboard. With help of Developer Dashboard we can get view of SharePoint enviroment and find out issues if occuring. This Provides us info about Call Stacks, Web Server, Critical Events, Database Queries, Service Calls, SP Requests, and Webpart Events. This even shows the time being taken to execute any code.

Under Database Calls this will even provide us the hyperlinks. We can click on the link and it will show us a dialog and we can see the SQL commands being Called.




Mode of developer dashboard:
On – creates everytime the output at the end of the page content
Off – switch off developer dashboard and nothing is rendered
OnDemand – creates a DeveloperDashboard icon to make dashboard output visible as needed

How to turn on Developer Dashboard?
Open Sharepoint 2010 Management Shell and type the following commands:

##Turn on
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService 
$dashboard = $contentService.DeveloperDashboardSettings
$dashboard.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$dashboard.Update()

##Turn on Demand Mode
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboard = $contentService.DeveloperDashboardSettings
$dashboard.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$dashboard.Update()

##Turn Off
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboard = $contentService.DeveloperDashboardSettings
$dashboard.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off
$dashboard.Update()

##Turn On demand using stsadm
stsadm -o setproperty -pn developer-dashboard -pv ondemand

Tuesday, August 2, 2011

Access denied error on SPWebApplication.Update()

While changing the default Access Denied page it was required to call update method SPWebApplication. But I received access denied error on SPWebApplication.Update().
The reason was that the Remote Administration Access Denied was true by default.

How to disable Remote Administration Access Denied?
Remote Administration Administration Access denied can disabled using command shell. Open Shell and run commands specified below:

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService
.RemoteAdministratorAccessDenied =
$false
$contentService
.Update()
 

Monday, August 1, 2011

How to use Custom Access Denied Page in SharePoint 2010?


I came across a situation where I need to replace default Access Denied Page of Sharepoint with my own custom Access Denied Page.
For this there is a method available in SPWebApplication class named 'UpdateMappedPage'. This method takes two parameters.
  1. The application page to replace with the specified custom application page. This is an enum of type Microsoft.SharePoint.Administration.SPWebApplication.SPCustomPage and with available values AccessDenied (Specifies AccessDenied.aspx)
     Confirmation (Specifies Confirmation.aspx)
     Error (Specifies Error.aspx)
     Login (Specifies Login.aspx)
     RequestAccess (Specifies ReqAcc.aspx)
     Signout (Specifies SignOut.aspx)
     WebDeleted (Specifies WebDeleted.aspx)
  2. The location of the custom application page. This must start with "/_layouts/".  If want to reset back to default then pass this as null.

Steps to make it working.

  1. Create empty Sharepoint Project.
  2. Create your costom Access Denied Page in Layouts e.g
    /_layouts/MyCustomLayout/AccessDenied.aspx
  3. Create a Feature and set scope to site. Add event receiver to this feature.


[Guid("ffcbe7bb-4093-4c39-953d-de07236c878c")]
    public class ReplaceDefaultPagesFeatureEventReceiver : SPFeatureReceiver
    {
        const string customAccessDeniedPage = "/_layouts/MyCustomLayout/AccessDenied.aspx";
       
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(site.ID, SPUserToken.SystemAccount))
                {
                    SPWebApplication webApp = _site.WebApplication;
                    if (null != webApp)
                    {
                        if (webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, customAccessDeniedPage))
                        {
                             webApp.Update();
                        }
                    }
                }
            });
        }


        //On deactivate set default access denied page
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(site.ID, SPUserToken.SystemAccount))
                {
                    SPWebApplication webApp = _site.WebApplication;
                    if (null != webApp)
                    {
                        if (webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, null))
                        {
                              webApp.Update();
                        }
                    }
                }
            });
        }
    }

You may receive access denied error on webApp.Update(). To solve that issue please visit on my other post http://www.anmolrehan-sharepointconsultant.com/2011/08/access-denied-error-on.html

Popular Posts