Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Configuring Applications LISTING 34.17 ProvisionSite.aspx Import Namespace=”System.IO” % Import Namespace=”System.DirectoryServices” % Import Namespace=”System.Web.Configuration” % const string wwwroot = @”c:\Inetpub”; const string sitePath = @”IIS://localhost/W3SVC/1/ROOT”; protected void btnSubmit_Click(object sender, EventArgs e) { string newFolder = Path.Combine(wwwroot, txtVirtualDir.Text); CreateVirtualDirectory(newFolder, txtVirtualDir.Text, txtVirtualDir.Text); CreateConfiguration(txtVirtualDir.Text); // Show link to new site lnkNewSite.NavigateUrl = “http://localhost/” + txtVirtualDir.Text; lnkNewSite.Target = “_top”; lnkNewSite.Visible = true; } private void CreateVirtualDirectory(string folderPath, string. | 1544 CHAPTER 34 Configuring Applications LISTING 34.17 ProvisionSite.aspx @ Page Language C @ Import Namespace System.IO @ Import Namespace System.DirectoryServices @ Import Namespace System.Web.Configuration DOCTYPE html PUBLIC - W3C DTD XHTML 1.0 Transitional EN http www.w3.org TR xhtml1 DTD xhtml1-transitional.dtd script runat server const string wwwroot @ c Inetpub const string sitePath @ IIS localhost W3SVC 1 ROOT protected void btnSubmit_Click object sender EventArgs e string newFolder Path.Combine wwwroot txtVirtualDir.Text CreateVirtualDirectory newFolder txtVirtualDir.Text txtVirtualDir.Text CreateConfiguration txtVirtualDir.Text Show link to new site lnkNewSite.NavigateUrl http localhost txtVirtualDir.Text lnkNewSite.Target _top lnkNewSite.Visible true private void CreateVirtualDirectory string folderPath string virtualDirectory-Name string appFriendlyName Create new Folder Directory.CreateDirectory folderPath Create Virtual Directory DirectoryEntry vRoot new DirectoryEntry sitePath DirectoryEntry vDir vRoot.Children.Add virtualDirectoryName IIsWebVirtualDir vDir.CommitChanges vDir.Properties Path .Value folderPath vDir.Properties DefaultDoc .Value Default.aspx vDir.Properties DirBrowseFlags .Value 2147483648 vDir.CommitChanges vRoot.CommitChanges Create Application Isolated vDir.Invoke AppCreate2 1 From the Library of Wow eBook Using the Configuration API 1545 vDir.Properties AppFriendlyName .Value appFriendlyName vDir.CommitChanges private void CreateConfiguration string virtualPath Open configuration Configuration config WebConfigurationManager.OpenWebConfiguration virtualPath Set language and debug setting Compilationsection section CompilationSection config.GetSection system.web compilation section.DefaultLanguage rdlLanguage.SelectedItem.Text section.Debug chkDebug.Checked Save configuration config.Save ConfigurationSaveMode.Modified script html xmlns http www.w3.org 1999 xhtml head id Head1 runat server title Provision Site title head body form id