About IIS(Internet Information Servicces)

Overview
Over the years, it has become simple for advanced Web users to create their own Web site. Once an end-user has registered their domain name, there are various types of hosters to choose from. Web hosters are available throughout the world to meet the demands of end customers. But regardless of which hoster is chosen, the scenario of signing up and creating a web site is similar in all cases.
Initially, a new user account needs to be established for the user. Once the account has been set up, the end user decides what features and options the site should incorporate: for instance, how much disk space, FTP capability, creation of virtual directories, whether or not databases are needed, etc. Hosters build control panels or dashboard applications that allow end users to create and manage these features.
There are a number of ways that these capabilities can be implemented into the control panel. In this section, we look at implementing the provisioning aspect of these features through managed code. An outline of the features is as follows:
Provision new user account
Create content storage
Create Application Pool
Create Web site
Create binding
Create root application
Create Virtual directory
Create FTP site
Provision New User Account
A user account is needed for the site owner who manages and maintains the site. The account can either be an Active Directory Account, or a local user account. To simplify the scenario, we only illustrate creating a local user account.
The following code fragments demonstrate the creation of a local account.
The System.DirectoryServices namespace must be specified.

public static bool CreateLocalUserAccount(string userName, string password)
{
try
{
if (string.IsNullOrEmpty(userName))
throw new ArgumentNullException("userName", "Invalid User Name.");
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException("password", "Invalid Password.");
DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
bool userFound = false;
try
{
if (directoryEntry.Children.Find(userName, "user") != null)
userFound = true;
}
catch
{
userFound = false;
}
if (!userFound)
{
DirectoryEntry newUser = directoryEntry.Children.Add(userName, "user"); newUser.Invoke("SetPassword", new object[] { password });
newUser.Invoke("Put", new object[] { "Description", "Application Pool User Account" }); newUser.CommitChanges();
newUser.Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
} return true;
}
Create Content Storage
The content storage requires specific permissions configured for users to manage their own contents. The following code fragment demonstrates how to set directory permissions using managed code in C#:

InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType controlType)
{
try
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(directoryPath);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(userAccount, rights, inheritanceFlags, propagationFlags, controlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
return true;
}
Furthermore, if disk quota is restricted, the following code fragment demonstrates how to set disk quota using managed code. To use the disk quota management, you must add reference to Windows Disk Quota management component; it resides under window\system32\dskquota.dll.

public static bool AddUserDiskQuota(string userName, double quota, double quotaThreshold, string diskVolume)
{
try
{
DiskQuotaControlClass diskQuotaCtrl = GetDiskQuotaControl(diskVolume); diskQuotaCtrl.UserNameResolution = UserNameResolutionConstants.dqResolveNone; DIDiskQuotaUser diskUser = diskQuotaCtrl.AddUser(userName);
diskUser.QuotaLimit = quota;
diskUser.QuotaThreshold = quotaThreshold;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
return true;
}

Create Application Pool
An application pool defines the settings for a worker process that hosts one or more IIS 7.0 applications, carrying out their request processing. The application pool is a unit of process isolation, since all request processing for an application runs within its application pool's worker processes.
It is also a unit of isolation from a security perspective, since the application pool can run with a different identity, and ACL all needed resources exclusively for itself to prevent applications in other application pools from being able to access its resources. The following code fragment demonstrates the creation of an application pool, setting the identity, and setting properties.

public static bool CreateApplicationPool(string applicationPoolName, ProcessModelIdentityType identityType, string applicationPoolIdentity, string password, string managedRuntimeVersion, bool autoStart, bool enable32BitAppOnWin64,ManagedPipelineMode managedPipelineMode, long queueLength, TimeSpan idleTimeout, long periodicRestartPrivateMemory, TimeSpan periodicRestartTime)
{
try
{
if (identityType == ProcessModelIdentityType.SpecificUser)
{
if (string.IsNullOrEmpty(applicationPoolName))
throw new ArgumentNullException("applicationPoolName", "CreateApplicationPool: applicationPoolName is null or empty.");
if (string.IsNullOrEmpty(applicationPoolIdentity))
throw new ArgumentNullException("applicationPoolIdentity", "CreateApplicationPool: applicationPoolIdentity is null or empty.");
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException("password", "CreateApplicationPool: password is null or empty.");
}
using (ServerManager mgr = new ServerManager())
{
ApplicationPool newAppPool = mgr.ApplicationPools.Add(applicationPoolName);
if (identityType == ProcessModelIdentityType.SpecificUser)
{
newAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser; newAppPool.ProcessModel.UserName = applicationPoolIdentity; newAppPool.ProcessModel.Password = password;
}
else
{
newAppPool.ProcessModel.IdentityType = identityType;
}
if (!string.IsNullOrEmpty(managedRuntimeVersion)) newAppPool.ManagedRuntimeVersion = managedRuntimeVersion; newAppPool.AutoStart = autoStart;
newAppPool.Enable32BitAppOnWin64 = enable32BitAppOnWin64; newAppPool.ManagedPipelineMode = managedPipelineMode;
if (queueLength > 0)
newAppPool.QueueLength = queueLength;
if (idleTimeout != TimeSpan.MinValue)
newAppPool.ProcessModel.IdleTimeout = idleTimeout;
if (periodicRestartPrivateMemory > 0) newAppPool.Recycling.PeriodicRestart.PrivateMemory = periodicRestartPrivateMemory; if (periodicRestartTime != TimeSpan.MinValue) newAppPool.Recycling.PeriodicRestart.Time = periodicRestartTime;
mgr.CommitChanges();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
return true;
}

0 Responses to "About IIS(Internet Information Servicces)"