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

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.

Related

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

How do I modify the Site Collection in SharePoint 2013?

When I try to open a form published from InfoPath I now get this error:
"The following location is not accessible, because it is in a different site collection:
https//portal/sites/forms/Daily%20Activity/Forms/template.xsn?SaveLocation=https//portal.alamedacountyfire.org/sites/forms/Daily%20Activity/&Source=https//portal.alamedacountyfire.org/sites/forms/Daily%2520Activity/Forms/AllItems.aspx&ClientInstalled=false&OpenIn=Browser&NoRedirect=true&XsnLocation=https//PORTAL/sites/forms/Daily%20Activity/Forms/template.xsn."
Correlation ID:12c0ab9c-caff-80a8-f1b4-64d81dcfa6ea
Following are some options that you can try:
1) Save the form template (.xsn) as the source files in the publish options. Look at the manifest file in notepad and see if you can find a reference to the incorrect location. If so, correct it and Republish the form.
2) Clear the InfoPath cache on that machine. Start->Run "infopath /cache clearall"
3) See if the site collection has a managed path, if so, give the proper url while publishing. The XSN might be getting deployed on the root site and throws error since the intended list does'nt exist.
I found this worked for me. Got the answer from another post.
"I had a similar problem and found it was due to the request management service routing from my web application host header to the server name.
There was a routing rule in my request management settings. I just disabled routing and the problem went away. I used the following powershell to disable it. "
$w = Get-SPWebApplication "http://webapphostname"
$r = $w | Get-SPRequestManagementSettings
$r.RoutingEnabled = $false
$r.Update()
You may want to configure it rather than disable it. Here’s a good resource to get you started:
http://www.harbar.net/articles/sp2013rm1.aspx

Deploy to azure then get 403 - Access Forbidden

I'm trying to deploy to Azure (Silverlight application); I've migrated my DB, updated connection strings and published my application to Azure but when I click the service URL I get this:
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
Any idea what I need to change?
Many thanks
If the name of your bundle matches the path in the file system then IIS on Azure will throw the 403 Forbidden error.
So if you have a path in your solution called /Content/css and you have a bundle name called bundles.Add(new StyleBundle("~/Content/css").Include( ... in BundleConfig.cs which is displayed like this #Styles.Render("~/Content/css") in your _Layout.cshtml file. Then you get that error.
I solved this by changing the name of my bundle from /Content/css to /Style/css
bundles.Add(new StyleBundle("~/Content/css").Include( ... in BundleConfig.cs becomes bundles.Add(new StyleBundle("~/Style/css").Include( ...
#Styles.Render("~/Content/css") in your _Layout.cshtml becomes #Styles.Render("~/Style/css") in your _Layout.cshtml
You can use any names you like there is no specific limitations. I imagine you can go ahead and rename the folders in your solution too and that should work.
NB: The name of the bundle turns into a virtual directory that the browser can request from. If it resembles a physical folder structure then it will throw back the 403.
I needed to use the full path to a page within the application as I hadn't set a default document in my web config e.g
<add value="Pages/Home.aspx"/>
I got the same error in my MVC project.
After some debugging I found that it was because I have removed all "default pages" in the Azure Portal.
I added a dummy "index.html"-record in the portal and then everything worked nicely again :)

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"

Associate an application pool to site with appcmd

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"...

Resources