SPWeb.IsRootWeb property
SharePoint 2013
Gets a Boolean value that indicates whether the site is the top-level website of the site collection.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Gets a Boolean value that indicates whether the site is the top-level website of the site collection.