How do I change the physical path of web site in IIS7 with APPCMD?

后端 未结 5 1111
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 03:24

I need to change the physical path of a web site through the command line via the appcmd.exe tool, but I can\'t figure out the syntax. Can someone help?

5条回答
  •  失恋的感觉
    2021-01-31 04:01

    To get a list of virtual directories by site and app name to help ensure you are attempting to set the right thing.

    C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml
    

    optionally pipe that |more and/or mode con cols=160 this regex pulled out the parts I wanted

    var q= from siteApp in config.XPathSelectElements("appcmd/APP")
            let appName=siteApp.Attribute(XNamespace.None+"APP.NAME").Value
                from app in siteApp.XPathSelectElements("application")
            let appPath=app.Attribute(XNamespace.None+"path").Value
            let pool=app.Attribute(XNamespace.None+"applicationPool").Value
            let vd=app.XPathSelectElements("virtualDirectory[@path]")
            let virtuals=vd.Select (v => new{VirDir=v.Attribute(XNamespace.None+"path").Value,PhysicalPath=v.Attribute(XNamespace.None+"physicalPath").Value})
            let xvirtuals=virtuals.Select (v => new{ VirDir=v.VirDir,
                PhysicalPath=v.PhysicalPath,
                EnvRoot=v.PhysicalPath.ToString().StartsWith("%")})
            select new{AppName=appName,AppPath=appPath, Pool=pool,Virtuals=xvirtuals};
    

    so then for a specific site it becomes appcmd.exe set vdir "DefaultWebSite/jms" -physicalPath:"c:\inetpub\wwwroot\mytargetPath"

    here's the variable substitutions:

    appcmd.exe set vdir " + appName + virt.VirDir + " -physicalPath:" + targetPath+"

    and to look at the config settings for just that site:

        C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml /path:/jms
    

    another usage to be aware of:

        C:\Windows\System32\inetsrv\appcmd.exe list apps /metadata /config:* /xml
    

提交回复
热议问题