3 min read

ADFS Login Customization

October 18, 2013

The purpose of this article is to show the intention and implemention of the most common modifications for the ADFS login page.

Out of the box the login form should look like this:

ADFS Login pageThe f.e. is by default the page url, this can confuse the user, due they expect something like “your login” or “Office365 Login”.

logo

To add a logo you simply edit the web.config file.

  • Comment out the section:

<!--
<add key=”logo” value=”logo.png” />
-->

  • And add the path to your logo file.

“hint” label [domainusername]

This label is part of the page’s localization, that means you have to edit the language resource file.

The localization files are stored under App_GlobalResources there you’ll find one file for every language CommonResources.en.resx.

Edit the file of your language an replace the “hint” with you definition.

Remove the heading title

In the root folder of the login page in the folder  MasterPages is a file named MasterPage.master. This file defines the look of the login page. To hide the title just comment this part out.

<!--
<div class="GroupLargeMargin">
<div class="TextSizeXLarge">
<asp:Label ID="STSLabel" runat"server"></asp:Label>
</div>
</div>
-->

Auto-Populate the Username Field of the Forms Sign-in Page When Signing in to Office 365

With Office365 and ADFS it’s possible to login from the microsoft Office365 login page or via a smart link to get directly redirected to the ADFS login page.

The Office365 login page will process the username you enter and if it’s a on premise user you’ll get redirected to the ADFS login page. By default the ADFS login page doesn’t care about the username you’ve provided at the Office365 login page. To populate the username into the login field the ADFS page has be modified like this:

Modify global.asax.cs

Process username from the url parameter.

  • Open global.asax.cs for editing
  • Find the following and set your cursor to the next line down:

public void Application_BeginRequest()
{

  • Paste the following code:

HttpRequest request = HttpContext.Current.Request;
HttpResponse response = HttpContext.Current.Response;

if ( !String.IsNullOrEmpty( request.Params["username"] ) )
{
     HttpCookie cookie = new HttpCookie( "Office365Username", request.Params["username"] );
     cookie.Expires = DateTime.UtcNow.AddMinutes( 10 );
     Response.Cookies.Add( cookie );
}

  • Save and Close global.asax.cs

Modify FormsSignIn.aspx.cs

Add the username parameter to the username box.

  • Open FormsSignIn.aspx.cs for editing
  • Find the following and set your cursor to the next line down:

using System;

Paste the following code:


using System.Web;

Find the following and set your cursor to the next line down:


protected void Page_Load( object sender, EventArgs e )
{

Paste the following code:


HttpCookie cookie = Context.Request.Cookies.Get( "Office365Username" );

if ( null != cookie && !String.IsNullOrEmpty( cookie.Value ) )
{
     UsernameTextBox.Text = cookie.Value;
     cookie.Expires = DateTime.UtcNow.AddDays( -1 );
     cookie.Value = "";
     Context.Response.Cookies.Add( cookie );
}

Save and Close FormsSignIn.aspx.cs

Categories:  Office 365

Tags:  adfs , office365

comments powered by Disqus