/// <Summary>
/// Check IIS and version number
/// </Summary>
/// <Returns> </returns>
Public String getiisverstion ()
{
Registrykey key = registry. localmachine. opensubkey (@ "SOFTWARE \ Microsoft \ inetstp ");
If (Key = NULL)
Return string. empty;
Else
Return convert. tostring (key. getvalue ("majorversion") + "." + convert. tostring (key. getvalue ("minorversion "));
}
From: http://www.cnblogs.com/wujy/archive/2011/10/07/2200813.html
Bytes --------------------------------------------------------------------------------------------------
Asp.net verifies the server folder permission
(1) directoryinfo dinfo = new directoryinfo (@ "D: \ Demo ");
If (dinfo. getdirectories (). isreadonly = true) // read-only
(2) Try to upload a file via try catch and throw an exception to check whether the exception is read-only.
Adddirectorysecurity (directoryname, "iis_iusrs", filesystemrights. readdata, accesscontroltype. Allow );
Removedirectorysecurity (directoryname, @ "domain \ Username", filesystemrights. readdata, accesscontroltype. Allow );
// Adds an ACL entry on the specified directory for the specified account.
Public static void adddirectorysecurity (string filename, string account, filesystemrights rights, accesscontroltype controltype)
{
// Create a new directoryinfo object.
Directoryinfo dinfo = new directoryinfo (filename );
// Get a directorysecurity object that represents
// Current security settings.
Directorysecurity dsecurity = dinfo. getaccesscontrol ();
// Add the filesystemaccessrule to the security settings.
Dsecurity. addaccessrule (New filesystemaccessrule (account,
Rights,
Controltype ));
// Set the new access settings.
Dinfo. setaccesscontrol (dsecurity );
}
// Removes an ACL entry on the specified directory for the specified account.
Public static void removedirectorysecurity (string filename, string account, filesystemrights rights, accesscontroltype controltype)
{
// Create a new directoryinfo object.
Directoryinfo dinfo = new directoryinfo (filename );
// Get a directorysecurity object that represents
// Current security settings.
Directorysecurity dsecurity = dinfo. getaccesscontrol ();
// Add the filesystemaccessrule to the security settings.
Dsecurity. removeaccessrule (New filesystemaccessrule (account,
Rights,
Controltype ));
// Set the new access settings.
Dinfo. setaccesscontrol (dsecurity );
}