ASP. NET environment detection before deployment

Source: Internet
Author: User

/// <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 );

}

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.