Warm Up Form Based Web Application

Normal warm up scripts for SharePoint open a site object or web object and make a request to that specific site. When you use form based authentication and do not allow anonymous access, you would only warm up the login page.

In order to warm up a application form based SharePoint site you would have to apply your credentials. All off this can be done by using PowerShell and specific COM objects. This script can then be scheduled with “Task Scheduler” that is included in windows.

function Warm-FBASite{
    [CmdletBinding()]
    param (
        [string] $RootUrl = $(Read-Host -prompt "Root Url"),
        [string] $LoginUrl = $(Read-Host -prompt "Login Url"),
        [string] $SiteUrl = $(Read-Host -prompt "Site Url"),
        [string] $UserName = $(Read-Host -prompt "Username"),
        [string] $Password = $(Read-Host -prompt "Password"),
        [bool] $loggedIn = $(Read-Host -prompt "Already logged in")
    )
    $ieMain=New-Object -ComObject "InternetExplorer.Application";
    if($loggedIn -ne $true){
        Login-FBA -RootUrl $RootUrl -LoginUrl $LoginUrl -UserName $UserName -Password $Password -Browser $ieMain;
    }
    Navigate-Site -RootUrl $RootUrl -SiteUrl $SiteUrl;
    $ieMain.Quit();

}

The Warm-FBASite function is the main function that calls other functions. This function needs the following parameters:

  • RootUrl: The root URL of the application you would like to warm up.
  • LoginUrl: The relative URL to the login page.
  • SiteUrl: The relative URL to the site you would like to warm up.
  • UserName: The username off the forms user.
  • Password: The password off the forms user.
  • LogginIn: Boolean value whether the user has already been logged in.

In this function we open a Com object of internet explorer and provide it as a parameter to the function “Login-FBA”.

function Login-FBA{
    [CmdletBinding()]
    param (
        [string] $RootUrl = $(Read-Host -prompt "Root Url"),
        [string] $LoginUrl = $(Read-Host -prompt "Login Url"),
        [string] $UserName = $(Read-Host -prompt "Username"),
        [string] $Password = $(Read-Host -prompt "Password"),
        $Browser = $(Read-Host -prompt "Browser")
    )

    $url = $RootUrl + $LoginUrl;

    Write-Host "Trying to login the user:" $UserName " on the Url: " $url -ForegroundColor Green
    $Browser.navigate($url);
    $Browser.visible=$false;

    if ((Wait-Browser $Browser -Url $url ) -eq $false){
        Write-Host "Something went wrong with requesting the page";
        return
    }else{
        $doc=$Browser.Document
    }

    $txtUsername=$doc.getElementByID("ctl00_PlaceHolderMain_signInControl_UserName"); #Replace by your own ID
    $txtPassword=$doc.getElementByID("ctl00_PlaceHolderMain_signInControl_password"); #Replace by your own ID
    $btnSubmit=$doc.getElementByID("ctl00_PlaceHolderMain_signInControl_login"); #Replace by your own ID
    
    $txtUsername.value=$UserName;
    $txtPassword.value=$Password;
    $btnSubmit.click();
    if ((Wait-Browser $Browser -Url $url ) -eq $false){
        return;
    }
}

This function tries to open the login page in the com object you send in the parameters. When this page is loaded it inserts the username and password in the login controls by finding these controls by there id.

In this function you will have to insert your own Id’s of the username textbox, password textbox and submit button. In this function you also see a reference to the “Wait-Browser” function. This function is created to make sure the site you are requesting in the COM object is fully loaded.

function Wait-Browser{
    [CmdletBinding()]
    param (
            $Browser = $(Read-Host -prompt "Browser"),
            $Url = $(Read-Host -prompt "Url")
    )

    $maxRetries=50;
    $retry = 2;
    $retryCount = 0;

    while ($Browser.Busy -eq $true){  
        Write-Host "Waiting for browser: " $URl  -ForeGroundColor Yellow;
        
        if ($retryCount -gt $maxRetries){
            return $false;
        }
        
        $retryCount++;
        start-sleep $retry ;
    } 

    return $true;
}

When the login request succeeds it is time to open the site and let that document load within the COM object. When the site is loaded it will write the page title to the PowerShell window.

function Navigate-Site{
    [CmdletBinding()]
    param (
        [string] $RootUrl = $(Read-Host -prompt "Root Url"),
        [string] $SiteUrl = $(Read-Host -prompt "Site Url")
    )

    $url = $RootUrl + $SiteUrl;

    $iePage=New-Object -ComObject "InternetExplorer.Application";
    $iePage.navigate($url);
    $iePage.visible=$false;
    $retryCounter=0
    
     if ((Wait-Browser $iePage -Url $url ) -eq $false){
        Write-Host "Something went wrong with requesting the page" -ForegroundColor Red;
        return
    }else{
        $doc=$iePage.Document
        Write-Host "Site Loaded: " $doc.title -ForegroundColor Green;
    }

    $iePage.Quit();    
}

To make use of these functions you only have to add these functions in PowerShell and call the “Warm-FBASite” function just like below.

Warm-FBASite -RootUrl "https://sharepointsite.com"  -LoginUrl "/_layouts/15/login.aspx" -SiteUrl "/client/35" -UserName "[form account name]" -Password "[password]" -LoggedIn $false;

Related Posts

SharePoint Rest API Handler SharePoint contains a lot of Rest API’s that can be used for many scenario’s. You could use them for example in desktop and windows phone applications...
Adding Azure App Service Application Settings with PowerShell Within Azure there is a option to change several configuration settings. When working with  Deployment Slots this means you have to click a lot within...
Creating the Release Template that runs after the Build – Part 3 With the component created in part 2 we can start using it to deploy applications to our SharePoint environment. We start by creating a new template. ...
Create a custom component to deploy SharePoint Solutions – Part 2 In the first part of the series we have adjusted a build template in order to copy content from source control to the drop location after the build. T...
Offline Installation SharePoint 2013 In many situation you would like to do a offline installation of SharePoint 2013 or you are required to do a offline installation because you do not h...
Configuring Web Site Binding with Release Management Release Management provides a continuous deployment solution that makes release cycles repeatable, visible, and more efficient by automating deploymen...

4 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.