Setting Web Site connection limit


I recently had to set a connection limit for two sites under IIS.

Below is where you find it in IIS under advanced settings Connection time out.

image

wow is it hard to find in the configuration Editor Gui.  In order to see it you must goto the root site then choose system.applicationHost sites

Once you choose that open the collection for the site you need to change then under that option you’ll see the connection time out.

image

Now since I was able to get to the site I could set and get it based on where it is now as IIS built the set so I just created a corresponding Get.

Here are the two functions I create as a result. With two helper functions for importing webadministration

function Get-WebSiteConnectionLimit
{
<#
.SYNOPSIS
Gets’s website connection limit
.DESCRIPTION
When passing site name it’ll return a time span object indicating the connection limit
if the site is not found then a null is returned.
.EXAMPLE
Get-WebSiteConnectionLimit -website MyWebSite
#>
param
(
[ValidateNotNullorEmpty()]
[string]$website
)
Add-WebAdministrationModule
if ((Get-Website).name | Where-Object{$_ -eq $website})
{
$limit = (get-WebConfigurationProperty -pspath ‘MACHINE/WEBROOT/APPHOST’ -filter “system.applicationHost/sites/site[@name=’$website’]/limits” -name ‘connectionTimeout’).value
$limit
}
else
{$null}
}
function Set-WebSiteConnectionLimit
{
<#
.SYNOPSIS
Sets’s website connection limit
.DESCRIPTION
Passing the site name and a Timespan variable for the time to set to will set the sites connection limit
This function will check to see if the site is valid. If the site is not found then a null is returned and nothing is set.
.EXAMPLE
Set-WebSiteConnectionLimit -website MyWebSite ( New-TimeSpan -Seconds ‘600’ )
#>
param
(
[ValidateNotNullorEmpty()]
[string]$website,
[ValidateNotNullOrEmpty()]
[timespan]$TimeSpan
)
Add-WebAdministrationModule
if ((Get-Website).name | Where-Object{$_ -eq $website})
{
Set-WebConfigurationProperty -pspath ‘MACHINE/WEBROOT/APPHOST’ -filter “system.applicationHost/sites/site[@name=’$website’]/limits” -name ‘connectionTimeout’ -value $TimeSpan
}
else
{$Null}
}

function Add-WebAdministrationModule
{
<#
.SYNOPSIS
imports webadministration if present
.EXAMPLE
Import-WebAdministrationModule
#>
if((get-module -name webadministration) -eq $Null)
{
import-module webadministration
}

}
function Remove-WebAdministrationModule
{
<#
.SYNOPSIS
Removes webadministration if present
.EXAMPLE
Remove-WebAdministrationModule
#>
if((get-module -name webadministration) -eq $Null)
{
remove-module webadministration
}
}

Now to set or get the connection Limit time out I just call my function:

get-WebsiteConnectionlimit and it returns a [TimeSpan] Object

So to set my connection limit all I need to do is call my function and pass it a timespan I wish it to be.

Set-WebSiteConnctionLimit –website ‘mysite’ –timepan ( New-TimeSpan -Seconds ‘600’ )

 

Thom

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s