« Previous Next »

Thread: how to vbs programatically enable parent path for an application folder inside IIS7

Last post 09-17-2009 4:09 AM by Leo Tang - MSFT. 8 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (9 items)

Sort Posts:

  • 09-07-2009, 1:47 AM

    how to vbs programatically enable parent path for an application folder inside IIS7

    Hi guys, here's my problem.

    After I use vbscript to programmatically add application + application pool. 

    Then go to IIS7 gui interface to check, the settings are correct.

    But  when I open up the site, it say compilation error: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.(raise of .net language file who call to library)

    I belief is due to the .net language not able to run properly due to programmatically adding application/pool. I tried to recycle Application Pool but not working.

    Then I go to IIS7, remove the application, and manually add the folder as application/pool again, now the site works.

    Do Not understand...  Why programatically not working but manually add is working.

  • 09-10-2009, 2:39 AM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

    Hi,

    To reproduce this issue, could you post the minimum of script sample here ?

    Leo Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • 09-11-2009, 1:34 PM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

    Hello,

    You may also want to disable CustomErrors and paste the exact error you are receiving.

    As you are getting a compilation error - it seems that IIS is able to deliver you to the site so it doesn't seem like a bad configuration would cause it but until we see the actual error that is being logged I couldn't say for sure.

    Brock Hensley
    Technical Support Representative
    http://www.ServerIntellect.com

    Managed Servers, 24x7 U.S. Support, Web Hosting Solutions.
  • 09-11-2009, 7:55 PM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

    Hi Leo,

    Here's the code. What I wish to have is: put a script into susan subfolder that will be inside a subdomain. Then turn the subfolder into application, and tied to the application pool of that domain. (iis7)

     

     'after create subfolder, need to make it as application, and tied to application pool, then only can run
    Dim masterdomain, sitename, apath, phypath, apool, fullget
    Dim oWebAdmin, strApplicationPath, strSiteName, strPhysicalPath, oApp

    dim freetrialfolder: freetrialfolder= "susan"

    'actual path
    masterdomain= "mydomain.com"
    phypath= "D:\inetpub\vhosts\" & masterdomain & "\httpdocs\stores\" & freetrialfolder

    'poolname
    apool= "mydomain.com(domain)(2.0)(pool)"   //note: I follow this format because when a new domain created by Plesk, the application pool is this format.

    Unluckily inside plesk, they still don't have the API to convert folder into application yet. That's why I gotta use vbs to do it.
                  
    'here onwards follow naming in IIS7 interface
    sitename= "stores.mydomain.com"
    apath= "/" & freetrialfolder
    fullget= "Application.SiteName='" & sitename & "',Path='" & apath & "'"

    After I run it, everything looks fine. The settings created at programmatic is same as manual way. But after created, thigs like vbhelper script inside AppCode just can't run.

    It seems like not able to compile and run .net language..

  • 09-11-2009, 8:10 PM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

     Eg: When I open up the login.aspx page, the following error shown.

     

    Server Error in '/' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30002: Type 'DBHelper' is not defined.

    Source Error:


    Line 15:         Dim loginID As String
    Line 16: Dim pwd As String
    Line 17: Dim objDBHelper As DBHelper
    Line 18: objDBHelper = New DBHelper

    Line 19: 
    Source File: D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\.....\loginProc.aspx.vb    Line: 17

     


    Line 1:    #ExternalChecksum("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx","{406ea660-64cf-4c82-b6f0-42d48172a799}","03D9EA19DD34BFC6B089153567B73320")
    Line 2: '------------------------------------------------------------------------------
    Line 3: ' <auto-generated>
    Line 4: ' This code was generated by a tool.
    Line 5: ' Runtime Version:2.0.50727.3074
    Line 6: '
    Line 7: ' Changes to this file may cause incorrect behavior and will be lost if
    Line 8: ' the code is regenerated.
    Line 9: ' </auto-generated>
    Line 10: '------------------------------------------------------------------------------
    Line 11:
    Line 12: Option Strict Off
    Line 13: Option Explicit On
    Line 14:
    Line 15: Imports Microsoft.VisualBasic
    Line 16: Imports System
    Line 17: Imports System.Collections
    Line 18: Imports System.Collections.Specialized
    Line 19: Imports System.Configuration
    Line 20: Imports System.Text
    Line 21: Imports System.Text.RegularExpressions
    Line 22: Imports System.Web
    Line 23: Imports System.Web.Caching
    Line 24: Imports System.Web.Profile
    Line 25: Imports System.Web.Security
    Line 26: Imports System.Web.SessionState
    Line 27: Imports System.Web.UI
    Line 28: Imports System.Web.UI.HtmlControls
    Line 29: Imports System.Web.UI.WebControls
    Line 30: Imports System.Web.UI.WebControls.WebParts
    Line 31:
    Line 32:
    Line 33: Partial Public Class LoginProc
    Line 34: Implements System.Web.SessionState.IRequiresSessionState
    Line 35:
    Line 36:
    Line 37: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",6)
    Line 38: Protected WithEvents Head1 As Global.System.Web.UI.HtmlControls.HtmlHead
    Line 39:
    Line 40: #End ExternalSource
    Line 41:
    Line 42:
    Line 43: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",11)
    Line 44: Protected WithEvents lblResult As Global.System.Web.UI.WebControls.Label
    Line 45:
    Line 46: #End ExternalSource
    Line 47:
    Line 48:
    Line 49: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",13)
    Line 50: Protected WithEvents lblMsg As Global.System.Web.UI.WebControls.Label
    Line 51:
    Line 52: #End ExternalSource
    Line 53:
    Line 54:
    Line 55: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",10)
    Line 56: Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
    Line 57:
    Line 58: #End ExternalSource
    Line 59:
    Line 60: Protected ReadOnly Property Profile() As System.Web.Profile.DefaultProfile
    Line 61: Get
    Line 62: Return CType(Me.Context.Profile,System.Web.Profile.DefaultProfile)
    Line 63: End Get
    Line 64: End Property
    Line 65:
    Line 66: Protected ReadOnly Property ApplicationInstance() As System.Web.HttpApplication
    Line 67: Get
    Line 68: Return CType(Me.Context.ApplicationInstance,System.Web.HttpApplication)
    Line 69: End Get
    Line 70: End Property
    Line 71: End Class
    Line 72:
    Line 73: Namespace ASP
    Line 74:
    Line 75: <System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()> _
    Line 76: Public Class test4_webshaper_loginproc_aspx
    Line 77: Inherits Global.LoginProc
    Line 78: Implements System.Web.IHttpHandler
    Line 79:
    Line 80: Private Shared __initialized As Boolean
    Line 81:
    Line 82: Private Shared __fileDependencies As Object
    Line 83:
    Line 84: <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Line 85: Public Sub New()
    Line 86: MyBase.New
    Line 87: Dim dependencies() As String
    Line 88:
    Line 89: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx.vb",912304)
    Line 90: CType(Me,Global.System.Web.UI.Page).AppRelativeVirtualPath = "~/susan/.../loginProc.aspx"
    Line 91:
    Line 92: #End ExternalSource
    Line 93: If (Global.ASP.test4_..._loginproc_aspx.__initialized = false) Then
    Line 94: dependencies = New String(1) {}
    Line 95: dependencies(0) = "~/susan/.../loginProc.aspx"
    Line 96: dependencies(1) = "~/susan/.../loginProc.aspx.vb"
    Line 97: Global.ASP.test4_..._loginproc_aspx.__fileDependencies = Me.GetWrappedFileDependencies(dependencies)
    Line 98: Global.ASP.test4_webshaper_loginproc_aspx.__initialized = true
    Line 99: End If
    Line 100: Me.Server.ScriptTimeout = 30000000
    Line 101: End Sub
    Line 102:
    Line 103: Protected Overrides ReadOnly Property SupportAutoEvents() As Boolean
    Line 104: Get
    Line 105: Return false
    Line 106: End Get
    Line 107: End Property
    Line 108:
    Line 109: <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Line 110: Private Function __BuildControl__control2() As Global.System.Web.UI.HtmlControls.HtmlTitle
    Line 111: Dim __ctrl As Global.System.Web.UI.HtmlControls.HtmlTitle
    Line 112:
    Line 113: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",7)
    Line 114: __ctrl = New Global.System.Web.UI.HtmlControls.HtmlTitle
    Line 115:
    Line 116: #End ExternalSource
    Line 117: Dim __parser As System.Web.UI.IParserAccessor = CType(__ctrl,System.Web.UI.IParserAccessor)
    Line 118:
    Line 119: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",7)
    Line 120: __parser.AddParsedSubObject(New System.Web.UI.LiteralControl("Untitled Page"))
    Line 121:
    Line 122: #End ExternalSource
    Line 123: Return __ctrl
    Line 124: End Function
    Line 125:
    Line 126: <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Line 127: Private Function __BuildControlHead1() As Global.System.Web.UI.HtmlControls.HtmlHead
    Line 128: Dim __ctrl As Global.System.Web.UI.HtmlControls.HtmlHead
    Line 129:
    Line 130: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",6)
    Line 131: __ctrl = New Global.System.Web.UI.HtmlControls.HtmlHead("head")
    Line 132:
    Line 133: #End ExternalSource
    Line 134: Me.Head1 = __ctrl
    Line 135:
    Line 136: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",6)
    Line 137: __ctrl.ID = "Head1"
    Line 138:
    Line 139: #End ExternalSource
    Line 140: Dim __ctrl1 As Global.System.Web.UI.HtmlControls.HtmlTitle
    Line 141:
    Line 142: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",6)
    Line 143: __ctrl1 = Me.__BuildControl__control2
    Line 144:
    Line 145: #End ExternalSource
    Line 146: Dim __parser As System.Web.UI.IParserAccessor = CType(__ctrl,System.Web.UI.IParserAccessor)
    Line 147:
    Line 148: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",6)
    Line 149: __parser.AddParsedSubObject(__ctrl1)
    Line 150:
    Line 151: #End ExternalSource
    Line 152: Return __ctrl
    Line 153: End Function
    Line 154:
    Line 155: <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Line 156: Private Function __BuildControllblResult() As Global.System.Web.UI.WebControls.Label
    Line 157: Dim __ctrl As Global.System.Web.UI.WebControls.Label
    Line 158:
    Line 159: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",11)
    Line 160: __ctrl = New Global.System.Web.UI.WebControls.Label
    Line 161:
    Line 162: #End ExternalSource
    Line 163: Me.lblResult = __ctrl
    Line 164: __ctrl.ApplyStyleSheetSkin(Me)
    Line 165:
    Line 166: #ExternalSource("D:\inetpub\vhosts\mydomain.com\httpdocs\stores\susan\...\loginProc.aspx",11)
    Line 167: __ctrl.ID = "lblResult"
    Line 168:
    Line 169: #End ExternalSource
    Line 170: Return __ctrl
    Line 171: End Function
    Line 172:

     

  • 09-15-2009, 6:48 AM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

    Hi,

    The code in your previous post did not show how to achieve this task. The following JavaScript sample convert the plain folder "susan" to an application. Most of codes are generated by Configuration Editor shipped with Administration Pack, you can do some test to see if it work for you.

    If you must to use Vbscript, you need to convert the Jscript to Vbscript manually.
    The Code samples in the following article  are presented in five languages, for your reference:
    http://www.iis.net/ConfigReference/system.applicationHost/applicationPools

    var masterdomain= "mydomain.com";
    var sitename= "stores.mydomain.com";
    var apool= "mydomain.com(domain)(2.0)(pool)";

    var freetrialfolder= "susan";
    var apath= "/" + freetrialfolder;
    var phypath= "D:\\inetpub\\vhosts\\" + masterdomain + "\\httpdocs\\stores\\" + freetrialfolder;

    var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
    adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

    //create the application pool

    var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");

    var applicationPoolsCollection = applicationPoolsSection.Collection;

    var addElement = applicationPoolsCollection.CreateNewElement("add");
    addElement.Properties.Item("name").Value = apool;
    applicationPoolsCollection.AddElement(addElement);


    adminManager.CommitChanges();

    //Convert the plain folder to an application

    var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");

    var sitesCollection = sitesSection.Collection;

    var siteElementPos = FindElement(sitesCollection, "site", ["name", sitename]);
    if (siteElementPos == -1) throw "Element not found!";
    var siteElement = sitesCollection.Item(siteElementPos);


    var siteCollection = siteElement.Collection;

    var applicationElement = siteCollection.CreateNewElement("application");
    applicationElement.Properties.Item("path").Value = apath;
    applicationElement.Properties.Item("applicationPool").Value = apool;

    var applicationCollection = applicationElement.Collection;

    var virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory");
    virtualDirectoryElement.Properties.Item("path").Value = "/";
    virtualDirectoryElement.Properties.Item("physicalPath").Value = phypath;
    applicationCollection.AddElement(virtualDirectoryElement);

    siteCollection.AddElement(applicationElement);


    adminManager.CommitChanges();


    function FindElement(collection, elementTagName, valuesToMatch) {
        for (var i = 0; i < collection.Count; i++) {
            var element = collection.Item(i);
           
            if (element.Name == elementTagName) {
                var matches = true;
                for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
                    var property = element.GetPropertyByName(valuesToMatch[iVal]);
                    var value = property.Value;
                    if (value != null) {
                        value = value.toString();
                    }
                    if (value != valuesToMatch[iVal + 1]) {
                        matches = false;
                        break;
                    }
                }
                if (matches) {
                    return i;
                }
            }
        }
       
        return -1;
    }

    If you have any problem , please update here.

    Leo Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • 09-15-2009, 8:19 AM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

     oops sorry, lack out of second portion of the code:

     Here's the full vbscript code I use to run application creation + application pool.

     

    Dim masterdomain, sitename, apath, phypath, apool, fullget
    Dim oWebAdmin, strApplicationPath, strSiteName, strPhysicalPath, oApp

    dim freetrialfolder: freetrialfolder= "susan"

    'actual path
    masterdomain= "mydomain.com"
    phypath= "D:\inetpub\vhosts\" & masterdomain & "\httpdocs\stores\" & freetrialfolder

    'poolname
    apool= "mydomain.com(domain)(2.0)(pool)"   //note: I follow this format because when a new domain created by Plesk, the application pool is this format.

    Unluckily inside plesk, they still don't have the API to convert folder into application yet. That's why I gotta use vbs to do it.
                 
    'here onwards follow naming in IIS7 interface
    sitename= "stores.mydomain.com"
    apath= "/" & freetrialfolder
    fullget= "Application.SiteName='" & sitename & "',Path='" & apath & "'"



    Dim oWebAdmin, strApplicationPath, strSiteName, strPhysicalPath, oApp

    'create application
    Set oWebAdmin= GetObject("winmgmts:root\WebAdministration")
    strSiteName= sitename    'follow the name list in IIS7
    strApplicationPath= apath     'sub from the IIS7 current namelist

    strPhysicalPath= phypath
    oWebAdmin.Get("Application").Create strApplicationPath, strSiteName, strPhysicalPath



    ' Specify the new application pool name.
    Set oApp = oWebAdmin.Get(fullget)
    oApp.ApplicationPool = apool
    oApp.Put_

  • 09-15-2009, 9:04 AM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

     I basically followed the code at http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-7-with-wmi/

    The settings are the same after creation, but it just won't work, .net language cannot run. However, when I create it manually via IIS7 interface, it works...

     

  • 09-17-2009, 4:09 AM In reply to

    Re: how to vbs programatically enable parent path for an application folder inside IIS7

    Hi,

    When you create the application manually via IIS7 Manager, the corresponding application pool was created automatically. You need to add code to create the application pool before assign an application to the application pool.

    oWebAdmin.Get("ApplicationPool").Create(apool)

    ' Specify the new application pool name.
    Set oApp = oWebAdmin.Get(fullget)
    oApp.ApplicationPool = apool
    oApp.Put_

    In this case, it seems  the .Net error was not caused by this issue. Please rebuild and publish your website , then test again.

    Leo Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (9 items)
Microsoft Communities