If you want to run a small job  such as notify, run a path code job, when administrators or power users on sites perform operations such as Create/Delete a site, Microsoft provide  The SPWebEventReceiver class provides methods that you can override to create these event handlers,
which are run in the following scenarios:

  • SiteDeleting. Before a site collection is deleted
  • SiteDeleted. After a site collection is deleted
  • WebDeleting. Before a site is deleted
  • WebDeleted. After a site is deleted
  • WebMoving. Before the Url of a site is changed
  • WebMoved. Before the Url of a site is changed
  • WebAdding. Before a new site is created
  • WebProvisioned. After a new site has been created

In this article, I will show you how to handle Web event receiver for the WebAdding event. This event receiver will use the  ConfigurationManager class to read the appSetting value. Based on the value of this setting, the Web event receiver either allows or disallows the creation of subsites.

  1. In the Solution Explorer window, right-click yoursolution, point to Add and then click New Item.
  2. Click Event Receiver.
  3. In the Name text box, type ControlSubsites, and then click Add. The SharePoint Customization Wizard appears.
  4. In the What type of event receiver do you want? list, click Web Events.
  5. In the Handle the following events checkbox list, check the A site is being provisioned checkbox.
  6. Click Finish.
    Visual Studio adds an event receiver class with stub methods for the event you chose to handle.
  7. Replace the existing code in the WebAdding event handler with the following code
string configuredValue = ConfigurationManager.AppSettings["YouKey"].ToString();
if (configuredValue == "1")
	properties.ErrorMessage = "Sub webs are not allowed";
	properties.Status = SPEventReceiverStatus.CancelWithError;
	properties.Cancel = true;

Since we are using ConfigurationManager, dont forget to add the namespage

using System.Configuration;
using System.Web;

Hope it help.
Hoang Nhut NGUYEN