Associate an application pool to site with appcmd - iis

I want create a site by command line using appcmd.
How can I associate a specific application pool to site?
To create a site, I write in this way:
appcmd add site /name:"prova" bindings:http://localhost:8080 /physicalPath:c:\sites\prova

You can do this:
APPCMD.exe set app "prova/" /applicationPool:"YOUR_APP_POOL_NAME_HERE"
Note the trailing slash appended to prova, that's important.
For example if I wish to set the application pool for prova to the DefaultAppPool I would issue the following command:
APPCMD.exe set app "prova/" /applicationPool:"DefaultAppPool"
Picking up from Chris's comment below, if you have an existing application in your site, say /mybloggy and you wish to change application pool it belongs to then you'd issue the following:
APPCMD.exe set app "prova/mybloggy" /applicationPool:"DefaultAppPool"

Alternative syntax:
APPCMD.exe set site /site.name:"Site name" /[path='/'].applicationPool:"App Pool Name"
Found in Windows Server docs:
https://technet.microsoft.com/en-us/library/cc732992(v=ws.10).aspx

Although the OP was looking to assign the app pool within the "add site" command, I couldn't find a way to include it with the original "add site" command. I got it working using "add site" followed by "set site" using syntax by Kev above.
On the other hand, if you ever need to add an "application" under that "site", you can specify the app pool when you use the "add app" command with the applicationPool argument as here:
APPCMD add app /site.name:"prova" /path:/App1 /physicalPath:c:\sites\prova\App1 /applicationPool:"provaAppPool"
p.s. You may need to prefix APPCMD with %systemroot%\system32\inetsrv\ and call
%systemroot%\system32\inetsrv\APPCMD /site.name:"prova"...

Related

appcmd.exe to overwrite a single site's entire xml config (applying the settings to a site that already exists)

I don't want to delete and recreate a site I just want to be able to apply the entire config to it and override any settings that are different.
I backed up the site config with %windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
This command throws an error:
appcmd.exe add site /in < c:\sites.xml
ERROR ( message:Failed to add duplicate collection element "mysite". )
Do I really have to break out ALL of my IIS configuration into separate appcmd commands or is there a way to apply the entire xml in one shot and only have it override settings?
I want to have a single xml template that I can push out to all my webservers hosting this site.
If you already exists installed sites then you must by have other ID for new site
<SITE SITE.NAME="NewSite" SITE.ID="1094096085" bindings="*" state="Started">
<site name="NewSite" id="1094096085" serverAutoStart="false">
Else you get conflict by ID
You should try shared config
http://www.iis.net/learn/manage/managing-your-configuration-settings/shared-configuration_264
Regarding:
ERROR ( message:Failed to add duplicate collection element "mysite". )
It seems that you can not add a website that already exist.
Why dont you delete it and add it again with the new configurations?
You can also try to modify only the relevant sections.

APPCMD how to test if binding exists before I add it to a website?

We use appcmd in our deployment scripts to setup servers , I need to ensure that adding bindings to existing sites doesn't throw an error
C:\Windows\System32\inetsrv\appcmd.exe set site /site.name:"abc.com"
/+bindings. [protocol='http',bindingInformation='*:80:alias-abc.com']
works but in the next script run I get the error ..
cannot add duplicate collection entry of type 'binding' with combined key attribuites 'protocol, bindingInformation' respectively set to '
http, *:alias-abc.com'
Is there a way I can check if the binding exists before adding it in appcmd
(powershell is not allowed - so has to be either appcmd or other command line exe)
Thanks
appcmd is a bit lacking in the search department, but something like this should work:
C:\Windows\system32\inetsrv\appcmd.exe list site "abc.com" | findstr bindings:http/*:80

Error using appcmd to add ssl binding

I want to add a binding to a site using appcmd. But when I try the following command I get an error:
appcmd set site /site.name:"My site name" /+bindings.[protocol='https',bindingInformation='*:443:sub.mydomain.com']
The error:
ERROR ( message:Cannot find SITE object with identifier "bindingInformation='*:443:sub.mydomain.com']". )
I checked if the site exists and it does. What am I doing wrong?
If you're using PowerShell, you have to surround the bindings parameter with double quotes so that PowerShell doesn't interpret the single quotes before the command is sent to appcmd.
./appcmd set site /site.name: contoso /+"bindings.[protocol='https',bindingInformation='*:443:']"
source: http://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx
Try this:
appcmd set site "My site name" /bindings:"https://sub.mydomain.com:443"
But your command is correct as well. List all websites and make sure you are using one of them:
appcmd list site
I ran into a problem in Powershell with the colons in the bindings. Concatenating them solved the issue.
[string] $cmd = "$Env:windir\SysWOW64\inetsrv\APPCMD.exe"
$response = invoke-expression "$cmd add site /name:""$SiteName"" /id:$ID /+""bindings.[protocol='$Protocol',bindingInformation='$IP"+":$Port"+":']"" /physicalPath:""$Path"""
You need to run your command as administrator.
I was never able to make this work with a wildcard certificate for *.mydomain.com with what I thought to be a quite friendly name: "mydomain.com plus wildcard". I'd run the commands above, go into IIS and look at the bindings and it would be there but without a certificate selected. Selecting the certificate would removed the host name and disable it so I couldn't change it.
I finally got it to work by changing the wildcard certificate's friendly name to the format expected by IIS ("*.mydomain.com") and adding it normally through the IIS interface, no idea if the above appcmd commands would work. The moral of this story is to give wildcard certs the standard form friendly name.
I created a batch file to achieve that:
#echo off
set /p sitename="Enter the site Name (as displayed in IIS): " %=%
set /p siteurl="Enter the site Host Header(the site url): " %=%
set /p siteip="Enter the site IP Address (ip address or *): " %=%
set /p siteprotocol="Enter the site Protocol (http, https, etc): " %=%
set /p siteport="Enter the site Port (80, 443): " %=%
appcmd set site /site.name:"%sitename%" /+bindings.[protocol='%siteprotocol%',bindingInformation='%siteip%:%siteport%:%siteurl%']
pause

MSdeploy deploys an MVC 2 application with wrong virtual directory name

I'm using MSbuild(v4.0.30319.1) and MSdeploy(v7.1.618.0) to deploy my ASP MVC 2 application on IIS(v7.5).
Here are the commands I run to do it:
msbuild.exe <path to my csproj>/MyMvcApp.csproj /t:Package /p:configuration=release;outDir=<my output dir>
and msdeploy:
msdeploy.exe -verb:sync -source:package='<MSBuildOutputDir>\_PublishedWebsites\Webui_Package\MyMVCApp.zip' -dest:auto
After build and deploy the application is deployed by address http://localhost/MyMVCApp_deploy and not by address http://localhost/MyMVCApp.
I did not expect that the _deploy will be in the address.
How can I fix this?
As Portalus commented you can control the name of the app in the properties page. I'll expand a bit on that answer here.
Configure the default value on PP/Web tab
By default when you package/publish your web project we will create an Web Deploy parameter named IIS Web Application Name which controls this value. The default value for this is
ProjectName_deploy. The reason why we put the _deploy suffix there is for IIS scenarios. So you may already have an IIS app with the name of ProjectName but its much less likely that you will have one named ProjectName_deploy. You can customize this value on the Package/Publish Web tab of the project properties. One thing to keep in mind if you go this route is that all of these settings are tied to a specif build configuration. So if you configure the settings on Debug and the create your package using Release those settings will not apply. See image below.
When you set this value it sets the MSBuild property, DeployIisAppPath, and you can use that if you want to have some logic relating to the value it gets.
Pass the parameter value on publish
If you want you can also just specify the value of this parameter when you are publishing. You have two primary approaches here.
Specify the value for the individual property
Specify the value for this and other properties in a file
1. Specify the value for the individual property:
You can use the -setParam parameter when calling msdeploy.exe to give a new value for that parameter. For example:
%msdeploy% -verb:sync -source:package=WebApplication3.zip -dest:auto -setParam:name="IIS Web Application Name",value="Default Web Site/FooBar"
2. Specify the value for this and other properties in a file
When you create a package in VS we automatically create for you a file named {ProjectName}.SetParameters.xml. This file is a simple XML file and it will contain all the parameters, along with their default values. You can update that file to include the correct parameter values and then pass it into msdeploy.exe (note: the file doesn't have to be named ...SetParameters.xml you can rename it to whatever you want). If you want to use this approach then just use the -setParamFile parameter when calling msdeploy.exe. Here is an example of the command line syntax for this:
%msdeploy% -verb:sync -source:package=WebApplication3.zip -dest:auto -setParamFile=WebApplication3.SetParameters.xml
Change the application name in the settings.
Right click the web project hit properties. Go to package/publish web, change the application name to use on the destiantion server from "default web site/mymvcapp_deploy" to "default website/mymvcapp"

Web2py default app

I am planning to publish my site soon on Dreamhost using passenger WSGI as mentioned in the dreamhost setup documentation.
My issue is that I am wanting www.mydomain.com to go directly to my new application, instead of needing to go to web2py.mydomain.com/MyApp/Default.
What is the best way to solve this issue? Do I use DNS redirects or can this be done through the web2py configuration?
Another option available since web2py version 1.83 (Aug 11, 2010):
Default Application, Controller, and Function
The name of the default application, controller and function can be changed from init, default, and index respectively to another name by setting the appropriate value in routes.py:
default_application = "myapp"
default_controller = "admin"
default_function = "start"
You can in web2py. You have two options:
1) call your app "init"
2) use routes to do the mapping. Create a file web2py/routes.py and in it add
routes_in=[('/','/MyApp/default/index')]

Resources