Using the application in ASP. IIS7

Source: Internet
Author: User

In the latest release of the Venus Portal, the installation program has been added, the following is said. NET to IIS7 operations. IIS7 operation and IIS5/6 are very different, in IIS7 added Microsoft.Web.Administration namespace, added Servermanager, site several large classes to operate IIS7.

Here are some core code that you can use directly

1) Create a virtual directory

When you set up a virtual directory, default Web site is used, which defaults to default Web site, and Createvdir requires two parameters: virtual path name and actual physical path

public static bool Createvdir (string vdir, String phydir)
{

Servermanager Servermanager = new Servermanager ();
Site mySite = servermanager.sites["Default Web Site"];
MYSITE.APPLICATIONS.ADD ("/" + VDir, Phydir);
Servermanager.commitchanges ();
return true;

}

The virtual directory under the default Web site is established here, and the above MySite is modified to

Site mySite = IISMANAGER.SITES.ADD ("Test", "http", "*:80:" + WebName + ". Intranet." + TLD, @ "c:\Webs\" + WebName);

You can create a Web site. The 2 differences are: you build a website. The preceding access schematic URL is Http://www.dotnetcms.org/book, and the latter is http://book.dotnetcms.org

Next Create the application pool

public static void Createapppool (String apppoolname)
{
Try
{
Servermanager Servermanager = new Servermanager ();
SERVERMANAGER.APPLICATIONPOOLS.ADD (AppPoolName);
ApplicationPool AppPool = Servermanager.applicationpools[apppoolname];
AppPool. Managedpipelinemode = Managedpipelinemode. Classic;
Servermanager.commitchanges ();
AppPool. Recycle ();
}
Catch
{ }
}

The Managedpipelinemode value MANAGEDPIPELINEMODE.CLASSIC;IIS7 here supports classic Classical mode and Interget integration mode, in Integrated mode

The custom handler and module may not be valid, and if you want to use Classic mode for compatibility with previous IIS5/6 versions, it is recommended to use the integrated approach.

The following code shows how to assign a virtual directory to an application pool, and IIS5/6 the biggest difference is that VDir is actually vdir path, so here is a "/" that represents a virtual path.

public static void Assignvdirtoapppool (String vdir, String apppoolname)
{

Try
{
Servermanager Servermanager = new Servermanager ();
Site site = servermanager.sites["Default Web site"];
Site. applications["/" + VDir]. Applicationpoolname = AppPoolName;
Servermanager.commitchanges ();
}
Catch
{

}

}


Finally add a delete operation

public static bool Deletevdir (string vdirname)
{
Try
{
Servermanager Servermanager = new Servermanager ();
Site mySite = servermanager.sites["Default Web Site"];
Microsoft.Web.Administration.Application application = mysite.applications["/" + vdirname];
MySite.Applications.Remove (application);
Servermanager.commitchanges ();
return true;
}
Catch
{
return false;
}
}

To this,. The basic functionality of the net Operation IIS7 has been implemented.

Using the application in ASP. IIS7

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.