Some time ago I have written the post about creating custom login page for SharePoint 2010. Many visitors asked me whether it works also for SharePoint 2013. The answer is: probably yes :). I haven’t tested it, but it should not cause any problems.

This way or another, I’ve decided to rewrite the page to be 100% SharePoint 2013 comaptibile.

At the end of this post You will find everything what’s needed to implement the solution in Your environment. Enjoy!

First, check how the default page looks like:

FBA_1

FBA_2

Now, the custom login page content:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SignInPage.aspx.cs" Inherits="zavaz.SignInPage.Pages.SignInPage, $SharePoint.Project.AssemblyFullName$" MasterPageFile="~/_layouts/15/simplev4.master" %>

<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@ Assembly Name="Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="SharepointIdentity" Namespace="Microsoft.SharePoint.IdentityModel" Assembly="Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

<SharePoint:ScriptLink runat="server" ID="scriptLink1" Name="<% $SPUrl:~Site/_layouts/15/zavaz.SignInPage/Scripts/jquery.min.js %>"></SharePoint:ScriptLink>
 <SharePoint:ScriptLink runat="server" ID="scriptLink2" Name="<% $SPUrl:~Site/_layouts/15/zavaz.SignInPage/Scripts/jquery.corner.js %>"></SharePoint:ScriptLink>
 <SharePoint:ScriptLink runat="server" ID="scriptLink3" Name="<% $SPUrl:~Site/_layouts/15/zavaz.SignInPage/Scripts/SignInForm.js %>"></SharePoint:ScriptLink>

<SharePoint:CssRegistration runat="server" ID="cssRegistration1" Name="<% $SPUrl:~Site/_layouts/15/zavaz.SignInPage/Styles/SignInPage.css %>"></SharePoint:CssRegistration>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">

<SharePoint:EncodedLiteral ID="ClaimsFormsPageTitle" runat="server" text="<%$Resources:wss,login_pagetitle%>" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">

<SharePoint:EncodedLiteral ID="ClaimsFormsPageTitleInTitleArea" runat="server" text="<%$Resources:wss,login_pagetitle%>" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderSiteName" runat="server"/>

<asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderMain" runat="server">

<div class="header">
 zavaz SharePoint 2013 Custom Login Page
 </div>
 <div class="separator"></div>
 <div class="content-wrapper">
 <div id="content" class="rounded">
 <asp:Login runat="server" ID="signInControl" class="control-login" FailureText="<%$Resources:wss,login_pageFailureText%>" MembershipProvider="FBAMembershipProvider"
 DisplayRememberMe="true" TextBoxStyle-Width="250px" RememberMeSet="true" LoginButtonStyle-CssClass="ms-buttonheightwidth" UserNameLabelText="User name" TextLayout="TextOnTop"
 PasswordLabelText="Password" LabelStyle-Font-Bold="false" LabelStyle-Font-Size="Large" LabelStyle-ForeColor="White" LabelStyle-Font-Names="Calibri" LabelStyle-CssClass="ms-standardheader ms-inputformheader"
 TextBoxStyle-CssClass="ms-input" CheckBoxStyle-Font-Bold="false" CheckBoxStyle-Font-Names="Calibri" CheckBoxStyle-ForeColor="White" CheckBoxStyle-CssClass="ms-standardheader ms-inputformheader" CheckBoxStyle-Font-Size="Large"
 FailureTextStyle-Wrap="true" FailureTextStyle-Font-Names="Calibri" FailureTextStyle-Font-Size="Small" LoginButtonStyle-Font-Names="Calibri" LoginButtonStyle-Font-Size="Large" LoginButtonImageUrl="/_layouts/15/images/docencryptionhh.png"
 LoginButtonType="Image" TitleText="" TitleTextStyle-ForeColor="White" TitleTextStyle-Font-Bold="true" TitleTextStyle-Wrap="true" TitleTextStyle-Font-Names="Calibri" TitleTextStyle-Font-Size="Larger" />

<asp:LinkButton runat="server" ID="lbInternalUsers" Text="Active Directory Login" Font-Names="Calibri" Font-Size="Small" CssClass="ms-standardheader ms-inputformheader" Font-Bold="true" ForeColor="Wheat" OnClick="lbInternalUsers_OnClick" />

<asp:Label runat="server" ID="lblError" Font-Bold="true" ForeColor="Red" EnableViewState="false"></asp:Label>
 </div>
 </div>

<SharePoint:EncodedLiteral runat="server" ID="ClaimsFormsPageMessage" EncodeMethod="HtmlEncode" Visible="false" />

</asp:Content>

The code behind:


using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.IdentityModel.Pages;
using Microsoft.SharePoint.Utilities;
using System;
using System.Web;

namespace zavaz.SignInPage.Pages
{
 public partial class SignInPage : FormsSignInPage
 {
 #region Events

protected void lbInternalUsers_OnClick(object sender, EventArgs e)
 {
 try
 {
 if (SPContext.Current != null && SPContext.Current.Site != null)
 {
 SPIisSettings iisSettings = SPContext.Current.Site.WebApplication.IisSettings[SPUrlZone.Default];
 if (iisSettings != null && iisSettings.UseWindowsClaimsAuthenticationProvider)
 {
 SPAuthenticationProvider provider = iisSettings.WindowsClaimsAuthenticationProvider;
 Redirect(provider);
 }
 }
 }
 catch (Exception ex)
 {
 lblError.Text = ex.Message;
 }
 }

#endregion

#region Private Methods

private void Redirect(SPAuthenticationProvider provider)
 {
 string comp = HttpContext.Current.Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);
 string url = provider.AuthenticationRedirectionUrl.ToString();
 if (provider is SPWindowsAuthenticationProvider)
 {
 comp = EnsureUrl(comp, true);
 }

SPUtility.Redirect(url, SPRedirectFlags.Default, this.Context, comp);
 }

private string EnsureUrl(string url, bool urlIsQueryStringOnly)
 {
 if (!url.Contains("ReturnUrl="))
 {
 if (urlIsQueryStringOnly)
 {
 url = url + (string.IsNullOrEmpty(url) ? "" : "&");
 }
 else
 {
 url = url + ((url.IndexOf('?') == -1) ? "?" : "&");
 }
 url = url + "ReturnUrl=";
 }
 return url;
 }

#endregion
 }
}

The result:

FBA_3

That’s all. To implement the page in Your environment follow the steps:

  1. Download the package.
  2. Copy zavaz.SignInPage folder to the C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS directory.
  3. Copy zavaz.SignInPage.dll to GAC(C:\Windows\Microsoft.NET\assembly\GAC_MSIL) using the gacutil.exe tool.
  4. Set web application’s custom login page to ~/_layouts/15/zavaz.SignInPage/Pages/SignInPage.aspx.