Administration, SharePoint

Introduction to System Status Notifications in SharePoint 2013

SharePoint 2013 implements new System Status Notifications designed to provide site users information about lifecycle events to include availability of upgrade, maintenance, and read-only states.

System Status Notifications present important information about a SharePoint deployment and its availability, whether during upgrades, routine maintenance,  or conversion to read-only. Users are kept “in the know” as they receive a prominent banner on their sites that provides insight into the activity being performed—helping reduce calls to the help desk and subsequent burden on IT.

Farm administrators and developers can configure System Status Notifications to provide additional information to users and adjust upgrade delays.

SPWebApplication Properties

UpgradeReminderDelay

The UpgradeReminderDelay property is used to enable users to suppress the upgrade availability System Status Notification for a specified period of time.  Farm administrators can configure the UpgradeReminderDelay to allow users to suppress the UpgradeAvailable reminder for a period of time or alternatively set the value to 0 which shows users an UpgradeRequired reminder.  The default value is 30 (days).

image

Figure 1 above illustrates the System Status Notification when the UpgradeReminderDelay is set to a value greater than 0.

image

Figure 2 above illustrates the System Status Notification when the UpgradeReminderDelay is set to 0.

Configuring the UpgradeReminderDelay SPWebApplication property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
    {
        static void Main(string[] args)
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepoint.contoso.com"));
            webApp.UpgradeReminderDelay = 90;
            webApp.Update();
        }
    }
}

Windows PowerShell

$webApp = Get-SPWebApplication http://sharepoint.contoso.com

$webApp.UpgradeReminderDelay = 90

$weApp.Update()

UpgradeMaintenanceLink

The UpgradeMaintenanceLink property is used to provide users additional information during the site collection upgrade process.  Farm administrators can use the UpgradeMaintenanceLink property to enable a More Information link in the System Status Notification during the upgrade process directing users to a location where more information is available related to the upgrade process.  The default value for the UpgradeMaintenanceLink property is null therefore no More Information link is displayed to users.

image

Figure 3 Illustrates the System Status Notification when the UpgradeMaintenanceLink is not null.

Configuring the UpgradeMaintenanceLink SPWebApplication property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
     class Program
     {
         static void Main(string[] args)
         {
             SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepoint.contoso.com"));
             webApp.UpgradeMaintenanceLink = "http://office.microsoft.com/en-us/sharepoint-help/training-courses-for-sharepoint-2013-HA104030990.aspx";
             webApp.Update();
         }
     }
}

Windows PowerShell

$webApp = Get-SPWebApplication http://sharepoint.contoso.com

$webApp.UpgradeMaintenanceLink =  “http://office.microsoft.com/en-us/sharepoint-help/training-courses-for-sharepoint-2013-HA104030990.aspx”

$webApp.Update()

ReadOnlyMaintenanceLink

The ReadOnlyMaintenanceLink property is used to provide users additional information when a site collection is set to read-only or a content database is configured to read-only in Microsoft SQL Server.  Farm administrators can use the ReadOnlyMaintenanceLink property to enable a More information link in the System Status Notification while a site collection or content database is in a read-only state.  The default value for the ReadOnlyMaintenanceLink is null therefore no More Information link is displayed to users.  For example, if a farm administrator would like to provide additional information on the read-only experience for users, the ReadOnlyMaintenanceLink can be configured with a More information link that directs users to http://technet.microsoft.com/en-us/library/dd793608.aspx#proc1.

image

Figure 4 Illustrates the System Status Notification when the ReadOnly property for a SPSite is set to $true.

image

Figure 5 Illustrates the System Status Notification when the content database for a SPSite is set to read-only.

Configuring the ReadOnlyMaintenanceLink SPWebApplication property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
     {
         static void Main(string[] args)
         {
             SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepoint.contoso.com"));
             webApp.ReadOnlyMaintenanceLink = "http://technet.microsoft.com/en-us/library/dd793608.aspx#proc1";
             webApp.Update();
         }
     }
}

Windows PowerShell

$webApp = Get-SPWebApplication http://sharepoint.contoso.com

$webApp.ReadOnlyMaintenanceLink = “http://technet.microsoft.com/en-us/library/dd793608.aspx#proc1”;

$webApp.Update()

NOTE

If a site collection or content database is set to read-only, the read-only message is displayed, upgrade status notifications are not displayed.  If ReadOnlyMaintenanceLink is not empty, a More Information link will be displayed.

If a site collection or content database is not read-only, and an upgrade is processing, “the site is currently being upgraded” is displayed.  If UpgradeMaintenanceLink is not empty, a More Information link will be displayed.

If a site collection or content database is not read-only, not upgrading, and the site is in 2010 mode, and current user is site collection admin:

  • If SPWebApplication.UpgradeReminderDelay is greater than 0, “upgrade is available” notification will be displayed. Clicking on the “remind me later” will update the SPSite.UpgradeReminderDate to be in n days, and dismiss the notification.
  • When SPWebApplication.UpgradeReminderDelay is 0, site admin will see “upgrade is required” notification. There will be no “remind me later” option. The notification will be displayed on every browse, and have to be manually dismissed each time.

 

UpgradeEvalSitesRetentionDays

The UpgradeEvalSitesRetentionDays SPWebApplication property is used to specify the default number days after which upgrade evaluation sites will be deleted. The expiration date for upgrade evaluation sites is set based on their creation date plus this value in days.  For example, in the event a site collection administrator requests an evaluation site collection, and that site collection is created on 4/16/2013, the evaluation site collection will be deleted on 5/16/2013 (the default value is 30 days).

image

Figure 6 Illustrates the System Status Notification when the UpgradeEvalSitesRetentionDays is set.

Configuring the UpgradeEvalSitesRetentionDays SPWebApplication property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
     {
         static void Main(string[] args)
         {
             SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepoint.contoso.com"));
             webApp.UpgradeEvalSitesRetentionDays = 90;
             webApp.Update();
         }
     }
}

Windows PowerShell

$webApp = Get-SPWebApplication http://sharepoint.contoso.com

$webApp.UpgradeEvalSitesRetentionDays = 90;

$webApp.Update()

SPSiteUpgradeThrottleSettings

This class stores the throttle settings for large site upgrade, for example, a farm administrator can throttle the upgrade of site collections with a specified number of sites.

See also SPSiteUpgradeThrottleSettings members (Microsoft.SharePoint.

SPSite Properties

UpgradeReminderDate

The UpgradeReminderDate SPSite property is used to specify a date after which site collection administrators will be reminded to upgrade the site collection.

Configuring the UpgradeReminderDate SPSite property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://sharepoint.contoso.com");

            System.DateTime today = System.DateTime.Now;
            System.TimeSpan duration = new System.TimeSpan(30, 0, 0, 0);

            site.UpgradeReminderDate.Add(duration);
        }
    }
}

Windows PowerShell

$site = Get-SPSite http://sharepoint.contoso.com

$today = Get-Date

$duration = $today.AddDays(30)

$site.UpgradeReminderDate.Add($duration)

ExtendUpgradeReminderDate

The ExtendUpgradeReminderDate SPSite property is used to extend the upgrade reminder date for a site collection by the days specified at UpgradeReminderDate.  When called, it adds SPWebApplication.UpgradeReminderDelay to the current time, stores it in SPSite.UpgradeReminderDelay.

Configuring the ExtendUpgradeReminderDate SPSite property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://sharepoint.contoso.com");
            site.ExtendUpgradeReminderDate();
        }
    }
}

Windows PowerShell

$site = Get-SPSite http://sharepoint.contoso.com

$site.ExtendUpgradeReminderDate()

More Information  

System Status Notifications are rendered through sending JavaScript to the page head and do not implement server-side controls.  The ExtendUpgradeReminderDate is implemented as an xmlHttp object that sends a REST call to web.Url/_api/Site/ExtendUpgradeReminderDate.

AllowSelfServiceUpgrade

The AllowSelfServiceUpgrade SPSite property is used to specify whether version to version upgrade is allowed on a site collection.  If the AllowSelfServiceUpgrade property is set to false site collection administrators will not be able to upgrade their site collection, if set to true, site collection administrators can perform a self-service (Deferred Site Collection Upgrade).  Farm administrators can control the upgrade process either en masse or selectively by disabling self-service upgrade.

image

Figure 7 illustrates configuring the AllowSelfServiceUpgrade SPSite property to $false.

Configuring the AllowSelfServiceUpgrade SPSite property:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Sample_Maintenance_Link_Code
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://sharepoint.contoso.com");
            site.AllowSelfServiceUpgrade = false;
        }
    }
}

Windows PowerShell

$site = Get-SPSite http://sharepoint.contoso.com

$site.AllowSelfServiceUpgrade = $false;

Summary

A completely revised, backward-compatible upgrade experience is designed to balance the needs of users with those of IT. Because changing software is often difficult, SharePoint Server 2013 enables IT to upgrade SharePoint Server 2010 without having to upgrade users’ sites and content. These upgrades are deferred to the users, allowing them to choose when the time is right.

New evaluation site collections allow users to request an evaluation of the upgrade prior to upgrading production content; if satisfied with the experience, site collection administrators then can upgrade their content. It’s important to note that whether you have deployed SharePoint Server 2010 on-premises or subscribe to SharePoint Online in Office 365, the full upgrade capability is available.

Standard
Uncategorized

Welcome to the Developer Dashboard

About the Developer Dashboard

The Developer Dashboard is an instrumentation framework  new to Microsoft SharePoint Foundation and Server 2010 that can help diagnose particularly, classes of bugs that are easy to introduce through custom code, but often difficult to isolate by providing information about the request execution time, the number and callstack of each SPRequest allocation, the number, callstack, and query text of WCF calls and more.

The Developer Dashboard appears in a frame on the bottom of each page and can exist in one of three (3) possible modes – On, Off, OnDemand.  When the Developer Dashboard is in the ‘On’ mode, it is always displayed in a frame on the bottom of the page for each request, conversely, when the Developer Dashboard is in the ‘Off’ mode, it is not displayed, and finally when the Developer Dashboard is in the ‘OnDemand’ mode, it can be displayed or hidden by selecting an icon on the upper right corner of a page.  (see illustrations).

Developer Dashboard

DeveloperDashboard

OnDemand Mode Icon

ShowHideMe 

Using the Developer Dashboard

The Developer Dashboard makes it easy for IT professionals and developers to identify common issues, for example, if a value exceeds acceptable ranges it will be displayed in red and by hovering your mouse over any value you can receive additional information about that value or how common methods to resolve it depending on the situation.

For developers you can monitor any piece of code by wrapping it in the SPMonitoredScope or even create custom monitors for your own resources through implementing  ISPScopedPerformanceMonitor and adding the monitor to the SPMonitoredScope.

Enabling the Developer Dashboard

The Developer Dashboard can be enabled and disabled through the SharePoint Administration Tool (STSADM) or through Windows PowerShell.  The following examples illustrate each method:

STSADM

‘On’ Mode

STSADM –o setproperty –pn developer-dashboard –pv On

‘Off’ Mode

STSADM –o setproperty –pn developer-dashboard –pv Off

‘OnDemand’ Mode

STSADM –o setproperty –pn developer-dashboard –pv OnDemand

But wait there’s more…

Suppose you’d like to only display the developer dashboard if one or more counters (acceptable values) are exceeded, there’s a way to do that too by running:

STSADM –o setproperty –pn developer-dashboard –pv expensiveoperationsonly

Windows PowerShell

See below.

Scripted (Windows PowerShell)

Optionally you can script the configuration of the Developer Dashboard – to do so copy the following script and save it to somefile.ps1.

Param ([String]$mode)

function Main()
{
  $dashboard = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
  $dashboard.DisplayLevel = $mode;
  $dashboard.RequiredPermissions =’EmptyMask’;
  $dashboard.TraceEnabled = $true;
  $dashboard.Update()

  Write-Host "Configured Developer Dashboard with mode $mode."
}

Open the Microsoft SharePoint 2010 Shell and change directories to where you saved somefile.ps1 and run ./somefile.ps1 OnDemand (or optionally On or Off).

Standard
Uncategorized

PowerShell and SharePoint Automation Examples Part 3

Automating your Microsoft SharePoint Products and Technologies installations can provide both consistency and efficiency while reducing the potential for human error.  This is the third post on the subject of leveraging PowerShell to provide configuration logic for your environment(s).  In this example we cover the configuration of Diagnostic Logging through PowerShell and a source Xml manifest.  For previous examples see http://blogs.technet.com/wbaer/archive/tags/Powershell/default.aspx.


Instructions




  1. Copy the source below into somefile.ps1.
  2. Copy the Xml source in DiagnosticsLogging.xml.

  3. In the Windows Powershell console call ./somefile.ps1

Source


#——————————————————————————-
# Function: Main
#
# Description: Main entry point for the script.  Loads the configuration source
#  Xml and initializes the foreach loop to iterate over a
#   collection of Xml nodes.
#
# Parameters: None
#——————————————————————————-


function Main()
{
  [xml]$cfg = Get-Content .DiagnosticLogging.xml


  if( $? -eq $false ) {
    Write-Host “Cannot load configuration source Xml $cfg.”
    return $false
  }


  $cfg.Configuration.DiagnosticLogging | ForEach-Object {
    new-DiagnosticLogging( $_ )
  }
}


#——————————————————————————-
# Function:  new-DiagnosticLogging
#
# Description:  This script enables you to do programmatically what you can do
#   manually through the user interface in the Logging and
#   Reporting section on the Central Administration Diagnostics
#   Logging page.
#
# Parameters:  None
#——————————————————————————-


function new-DiagnosticLogging( [object] $cfg )
{
  [Void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Sharepoint”)


  if (!(Test-Path -Path $cfg.LogLocation))
  {
    New-Item $cfg.LogLocation -type directory
  }


  $SPDiagnosticsService = [Microsoft.SharePoint.Administration.SPDiagnosticsService]::Local
  $SPDiagnosticsService.LogLocation = $cfg.LogLocation
  $SPDiagnosticsService.LogsToKeep = $cfg.LogsToKeep
  $SPDiagnosticsService.LogCutInterval = $cfg.LogCutInterval


  Write-Host ([Environment]::NewLine+”DiagnosticsService.PS1 is making the requested changes.  This may take several minutes to complete.”)


  $SPDiagnosticsService.Update()


  $ErrorReporting = [Microsoft.SharePoint.Administration.SPWebService]::AdministrationService
 
  if( $cfg.ErrorReportingEnabled.ToString().ToLower() -eq “true” ) {
    $ErrorReporting.Farm.ErrorReportingEnabled = $true
  }
  elseif( $cfg.ErrorReportingEnabled.ToString().ToLower() -eq “false” ) {
    $ErrorReporting.Farm.ErrorReportingEnabled = $false
  }


  if( $cfg.ErrorReportingAutomaticUpload.ToString().ToLower() -eq “true” ) {
    $ErrorReporting.Farm.ErrorReportingAutomaticUpload = $true
  }
  elseif( $cfg.ErrorReportingAutomaticUpload.ToString().ToLower() -eq “false” ) {
    $ErrorReporting.Farm.ErrorReportingAutomaticUpload = $false
  }
}


main

Source Xml


<?xml version=”1.0″ encoding=”utf-8″?>
<Configuration>
  <![CDATA[ SPDiagnosticsService (Microsoft.SharePoint.Administration) ]]>
  <DiagnosticLogging>
    <ErrorReporting>
      <ErrorReportingEnabled>True</ErrorReportingEnabled>
      <ErrorReportingAutomaticUpload>True</ErrorReportingAutomaticUpload>
    </ErrorReporting>
    <LogCutInterval>96</LogCutInterval>
    <LogLocation>C:SomePath</LogLocation>
    <LogsToKeep>10</LogsToKeep>
  </DiagnosticLogging>
</Configuration>

Standard
Uncategorized

Developing SharePoint Applications

Do you have questions or are you looking for best practices on integrating line of business applications with Microsoft SharePoint Products and Technologies, taking advantage of publishing and content oriented capabilities, or creating collaborative interactions around business processes?  If you answered yes to any of these questions, I’d recommend reading the just published content, Developing SharePoint Applications, in the Patterns and Practices Developer Center


This guidance will help developers and architects accelerate construction of advanced applications through both examples and documentation, ensures alignment with recommendations and best practices and compliments existing platform documentation.


Related Resources


Microsoft Office SharePoint Server Developer Center


Windows SharePoint Services 3.0 SDK


SharePoint Server 2007 SDK


 

Standard
Uncategorized

Quota Templates and Powershell

Continuing the series using Powershell and Microsoft SharePoint Products and Technologies, this weeks script sample illustrates how Powershell can be leveraged to programmatically provision Quota Templates in Windows SharePoint Services 3.0 and/or Microsoft Office SharePoint Server 2007.

Instructions

  1. Copy the source below into somefile.ps1.
  2. Copy the Xml source in QuotaTemplates.xml.
  3. In the Windows Powershell console call ./somefile.ps1

Source

#——————————————————————————-
# Function:    main
#
# Description:    Main entry point for the script.  Loads the configuration source
#        Xml and initializes the foreach loop to iterate over a
#         collection of Xml nodes.
#
# Parameters:    None
#——————————————————————————-

function main()
{
  [xml]$cfg = Get-Content .QuotaTemplates.xml

  if( $? -eq $false ) {
    Write-Host "Cannot load configuration source Xml $cfg."
    return $false
  }

  $cfg.Configuration.QuotaTemplates.QuotaTemplate | ForEach-Object {
    new-QuotaTemplates( $_ )
  }
}

#——————————————————————————-
# Function:     new-QuotaTemplates
#
# Description:     This script enables you to do programmatically what you can do
#         manually through the user interface in the SharePoint Site
#         Management section on the Central Administration Quota
#         Templates page.
#
# Parameters:     None
#——————————————————————————-

function New-QuotaTemplates( [object] $cfg )
{
  [Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")

  $webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
  $quota=New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate

  $quota.Name = $cfg.Name
  $quota.StorageMaximumLevel = $cfg.StorageMaximumLevel
  $quota.StorageWarningLevel = $cfg.StorageWarningLevel

  $webService.QuotaTemplates.Add($quota);

  $webService.Update();
}

main

Source Xml

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <![CDATA[SPQuotaTemplate (Microsoft.SharePoint.Administration)]]>
  <QuotaTemplates>
    <QuotaTemplate Name="2GB">
      <StorageMaximumLevel>2097152000</StorageMaximumLevel>
      <StorageWarningLevel>1887436800</StorageWarningLevel>
    </QuotaTemplate>
    <QuotaTemplate Name="3GB">
      <StorageMaximumLevel>3145728000</StorageMaximumLevel>
      <StorageWarningLevel>2936012800</StorageWarningLevel>
    </QuotaTemplate>
    <QuotaTemplate Name="4GB">
      <StorageMaximumLevel>4194304000</StorageMaximumLevel>
      <StorageWarningLevel>3670016000</StorageWarningLevel>
    </QuotaTemplate>
    <QuotaTemplate Name="5GB">
      <StorageMaximumLevel>5242880000</StorageMaximumLevel>
      <StorageWarningLevel>4718592000</StorageWarningLevel>
    </QuotaTemplate>
    <QuotaTemplate Name="10GB">
      <StorageMaximumLevel>10485760000</StorageMaximumLevel>
      <StorageWarningLevel>9961472000</StorageWarningLevel>
    </QuotaTemplate>
    <QuotaTemplate Name="100GB">
      <StorageMaximumLevel>104857600000</StorageMaximumLevel>
      <StorageWarningLevel>99614720000</StorageWarningLevel>
    </QuotaTemplate>
  </QuotaTemplates>
</Configuration>

Standard
Uncategorized

Alternate Access Mappings and Windows Powershell

I had a request this week on how to leverage Windows Powershell to add Alternate Access Mappings to the collection for a specific Web application.  Surprisingly after some searching I was unable to find anything existing on the topic, so for those curious see the attached script and corresponding source Xml.

Instructions

  1. Copy the source below into somefile.ps1.
  2. Copy the Xml source in AAM.xml.
  3. In the Windows Powershell console call ./somefile.ps1.

Source

#——————————————————————————-
# Function:    main
#
# Description:    Main entry point for the script.  Loads the configuration source
#        Xml and initializes the foreach loop to iterate over a
#         collection of Xml nodes.
#
# Parameters:    None
#——————————————————————————-

function main()
{
  [xml]$cfg = Get-Content .AAM.xml

  if( $? -eq $false ) {
    Write-Host "Cannot load configuration source Xml $cfg."
    return $false
  }

  $cfg.Configuration.WebApplication | ForEach-Object {
    new-SPAlternateUrl( $_ )
  }
}

#——————————————————————————-
# Function:     New-SPAlternateURL
#
# Description:     This script adds the specified URLs to the collection of
#        alternate request URLs for the Web application.
#
# Parameters:    None
#——————————————————————————-

function New-SPAlternateURL( [object] $cfg )
{
  [Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")

  $webApp = $nul;
  $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($cfg.Url)
  trap [Exception] { 
      Write-Host
    Write-Error $("Exception: " + $_.Exception.Message);
    continue;
  }

  $cfg.AlternateUrl | ForEach-Object {
  $map=New-Object Microsoft.SharePoint.Administration.SPAlternateUrl($_.IncomingUrl, $_.UrlZone)
  $webApp.AlternateUrls.Add($map)
  return $map
  }

main

Source Xml

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <WebApplication Url="http://contoso">
    <AlternateUrl IncomingUrl="http://www.contoso.com" UrlZone="Internet" />
    <AlternateUrl IncomingUrl="http://contoso:1234" UrlZone="Custom" />
    <AlternateUrl IncomingUrl="http://contoso:4321" UrlZone="Custom" />
  </WebApplication>
</Configuration>

Standard
Uncategorized

HTTP to HTTPS Redirection with SharePoint Products and Technologies

I’ve received several requests in regards to redirecting HTTP to HTTPS.  In this post I will briefly cover a select number methods and/or technologies that can be used to accomplish HTTP to HTTPS redirection.

ISA 2006

Modify the Web Listener connection properties to enable HTTP to HTTPS redirection (see below).

  1. Open Web Listener Properties on the Published Site.
  2. Select the Connections Tab.
  3. Select Redirect all Traffic from HTTP to HTTPS under HTTP to HTTPS Redirection.

Port Forwarding

In a port forwarding scenario you would allow an arbitrary inbound port on your router and configure a destination (forwarded) IIS Website on port 80 that implements native IIS redirection to forward the request to the SSL secured Web application.  This solution provides the highest level of security and requires the least amount of customization on behalf of your Web application; however, port forwarding is not supported by all devices, may not be offered by your network engineering team, or conflicts with other corporate policies, etc.

403.x Modification

In this scenario you would modify the header if the 403.x to implement a META REFRESH to redirect clients to a specified Url.  This solution provides a level of security; however, the redirect is limited to a static Url and in many cases is not supported by all browsers (NOTE This is a proprietary extension to HTML, introduced by Netscape but supported by most web browsers), individual configurations, requires modification of IIS system files, and also does not communicate information about the source or destination to the browser.

HTTP Module

The following sample illustrates a HTTP module that replaces the http prefixes with https and handles the request.  In the sample code each event handler in this HTTP module is written as a private method of the module and when registered events are raised, ASP.NET will call the appropriate handler in the module.  The implementing (base) class provides initialization and disposal events through the IHttpModule Interface (System.Web namespace).

The IHttpModule Interface provides module initialization and disposal events to the implementing class.  An initialization function registers HttpApplication events by adding an OnBeginRequest as the handler.  HttpApplication and HttpContext event objects are created to access the request and response properties in the handler.  The intrinsic request object for the current request are obtained by getting information about the Url of the current request as a canonical string representation of the instance.  If the beginning of the instance matches http: a replace method is called to replace that occurrence with another specified string as https:.  An intrinsic response object is then called for that request and redirects the client to a new Url and terminates execution of the current page.  As a finalizer any current buffered output to the client is stopped in addition to execution of the page and a HttpApplication.EndRequest event raised.

NOTE The HTTP module approach requires removing the SSL required setting in Internet Information Services to permit the HTTP module to be loaded; otherwise, the request is thrown to the 403.x.

Sample Code

using System;
using System.Web;
[assembly: CLSCompliant(true)]

namespace Microsoft.SharePoint.SslRedirect
{
    public class RedirectModule : IHttpModule
    {
        #region IHttpModule Members
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(OnBeginRequest);
        }

        private void OnBeginRequest(object src, EventArgs e)
        {
            HttpApplication context = src as HttpApplication;
            string httpUrl = context.Request.Url.ToString();

            if (httpUrl.StartsWith("http:"))
            {
                httpUrl = httpUrl.Replace("http:", "https:");
                context.Response.Redirect(httpUrl.ToString(), false);
                context.CompleteRequest();
            }
        }

        public void Dispose()
        {
        }
        #endregion
    }
}
Standard