How can I turn on DynamicCompression feature of IIS programmatically? - iis-7

I'm making an installer program for my web application. My web application uses CSS and JS heavily, so I want to enable both Static and Dynamic HttpCompression for IIS7/7.5.
It needs 2 steps:
I can modified the web.config, put <httpcompression> tag, it's ok.
DynamicContentCompression must be turned on in Windows Feature to make httpCompression work.
Static HttpCompression is enable by default in IIS7 and IIS7.5, but Dynamic HttpCompression is not enable by default (although it's available). I can do manually by turn on: Start/ControlPanel/ProgramsAndFeatures/TurnWindowsFeatures on or Off/IIS/WWW Service/Performance features/Dynamic Content Compression, but How can I programmatically turn it on that Windows Feature?
I can use PowerShell, C# in my installer.
Any idea how I might be able to do this? Thanks.

This is the way I would have done it:
dism /online /enable-feature /featurename:IIS-HttpCompressionDynamic
dism allows you to check the return code of command, allowing you to verify that it worked (or was already installed)

These PowerShell commands will add add the Dynamic Compression feature.
Import-Module ServerManager
Add-WindowsFeature Web-Server, Web-Dyn-Compression
Don't forget to Run As Administrator or have administrator rights.

You can turn this on using the appcmd tool. From a command line:
C:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True
Or if you want to execute it from within a PowerShell script:
& $env:windir\system32\inetsrv\appcmd set config -section:urlCompression /doDynamicCompression:true
You're going to need administrative privileges to do either.

Disclaimer: this is totally unproven and untested ....
Greg's answer above is nearly right, but that only unlocks the installed feature. By default, when that feature is installed, it's locked down ... all the way down at the machine level.
The rational is because dynamic compression can really frak with the servers CPU. So in a hosting environment, this could kill things. Even with your own dedicated server, it could also kill things badly. So the safe route is to lock it by default and only if u know what you're doing, then go and unlock it.
So .. having a quick google search, i came to this page.
Notice how this technet article has a commandline thingy to install all the required packages for a sample static IIS server. I know your question is not for a static IIS server ... but it does higlight the commands possible.
So i'm guessing ... maybe this? ::
Start /w pkgmgr /iu:IIS-HttpCompressionDynamic
?? maybe :)
here's another article with more options...

Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic

Related

Machine Key generation feature not exist in latest IIS Version

Answering one of the recent question on SO, i encountered this anomaly.
This msdn blog suggests using IIS to generate machine key, which looks more secure to me as Microsoft tool being used. However, it seems this feature is only supported until IIS 7 or less.
I don't find it on my box IIS 8.5. I checked on IIS 7.5 and its not present there either. However, I found it in IIS 6.1 on a coworker box.
I am wondering whether:
It still exist in IIS latest versions, if yes, how to use it?
If it is removed from latest version of IIS, what's suggested approach from Microsoft to generate a secure enough machine key?
Is it safe to use these custom generators?
a. Machine Key Generator (online)
b. ASP.NET machineKey Generator (tool you can modify)
See https://support.microsoft.com/kb/2915218#AppendixA for information on how to generate a <machineKey> element. There's a script there that you can copy & paste into a Powershell window.
Reminder: only use keys that you generated yourself on your own machine. Never use an online generator.
As for mentioned by #ryanulit, you can just copy the script directly to your PowerShell window
Steps :
Open powershell window (anywhere is fine)
Copy the script from the microsoft link and paste in your powershell window and press enter
Type Generate-MachineKey -validationAlgorithm SHA1
That's it. Your machine key description will show up in the window.
PowerShell image sample from my PC
Script Link from Microsoft http://support.microsoft.com/kb/2915218#AppendixA
I know I came to very late to provide this answer. Hope this helps for any others.
I'm using the latest IIS 10(which is the latest)
By default, the Machine Key feature is not installed when enabling the Internet Information Service in the windows features.
You need to install ASP.NET XX from the World Wide Web Service
After installing this, you can generate your keys from the Machine Key Option.
Make a copy of the administration.config file in C:\Windows\System32\inetsrv\config. Then, in the <moduleProviders> node under <!-- ASP.NET Modules--> remove the MachineKey node. Then run iisreset. Re-open IIS and see if the ASP.NET area is present. If it is, put the MachineKey node back in the administration.config file (or just re-instate the original config file) and run iisreset again.

32 Bit App Pool on Server 2012 with Exchange

Ok so I have been keeping up with decompressing application pools and adding Pre Conditions to the applicationhost.config file. I am now stumped on server 2012.
Symptom:
Application Pool keeps crashing, even log error kicks off 4 listener channel errors and then kills the the app pool.
Previous Fix for older version servers:
Backup IIS. I add Pre Condtions to exppw and (and in this case)cafe_exppw. Additionally I add it to Kerbauth (In some cases the Pre Condtion was not needed.) Save. ResetIIS. I then run Anilr's script (ref:http://forums.iis.net/t/1149768.aspx) below which does not work. I am no programmer so I am not sure where to find an update version (if there is one) for 2012
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+[name='xpress',doStaticCompression='false',dll='%windir%\system32\inetsrv\suscomp.dll']
Thanks,
Jack
Often a problem with the 64 bit rpcproxy.dll which is loaded by iis by default even when "enable 32 bit applications" is set to true.
Here's a link that explains
http://blogs.technet.com/b/sbs/archive/2011/04/07/how-to-run-a-32bit-web-application-on-sbs-2008.aspx
Could be the source of your problem
Wing
For anyone who might be wondering how I got around this, just add "bitness64" /> to kerbauth and anything exppw in GlobalModules in the web.config file. Reboot IIS, verify OWA still works and that should do it. You might see some kerbauth errors but I am yet to see any real issue stem from it.
For your information there is no need to decompress the app pool:
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-[name='xpress']

HTTP Binding missing in IIS

Using IIS 7.5
Under binding type, these are the options that I see... but there's no http option available.
Binding type: - net.tcp - net.pipe - net.msmq - msmq.formatname
How can I get HTTP in there? I've tried un-installing IIS and reinstalling it, didn't help..
In case anyone else has this problem my final solution was to:
Remove WAS (Windows Activation Services)
Remove IIS
Reboot
Install WAS
Install IIS
Reboot
After that second reboot all of my bindings were back... Yay :)
Go to Control panel --> Programs and Features
1) Turn Windows features on or off
2) Unchecked "Internet Information Services" (IIS) and "Windows Process Activation Service" (WAS)
3) OK ....
4) You must restart your computer
When the Windows started
Go to Control panel --> Programs and Features
1) Turn Windows features on or off
2) Checked "Internet Information Services" (IIS) and "Windows Process Activation Service" (WAS)
3) OK
Good Luck!!
I find that most of the answers below are overkill. What's missing is the definition of http listenerAdapter in C:\WINDOWS\System32\Inetsrv\Config\applicationhost.config
Open the file in an editor (as admin), look for the <listenerAdapters> tag. My bet is that it does not list the "http" adaptor.
Add this line: <add name="http" /> immediately after <listenerAdapters>, save and exit.
Issue iisreset command as Administrator; restart IIS Manager - the selector is now in place
Question was asked quite a while ago but I figured I should post my solution since it ate up quite a bit of time and none of the suggested solutions here fixed it for me.
If you navigate to applicationHost.config, mine was under C:\Windows\System32\inetsrv\Config. Open it up and make sure you see http under listenerAdapters. Example shows https but you can do the same for http.
<listenerAdapters>
<add name = "https"/>
</listenerAdapters>
Solution was found from https://forums.iis.net/t/1177049.aspx?Problems+creating+a+new+site
I will add this for other dev's who will stumble this issue in the future.
The answers above are correct but there are times that you need also to disable
Hosted Web Core Applications IIS feature in order for your findings to be visible.
I have been having some similar issues, albeit slightly different setup. Mine was with IIS 10. When attempting to add a new site the binding type field was empty, there was no IP address or Port entry fields. numerous uninstall/re-installs didn't work either. In the end was the solution was to replace the config files located in C:\Windows\System32\Inetsrv\Config. Namely the applicationHost.config, administration.config & redirection.config. I pulled these from a clean install. As always you should take a backup before doing this, also please note that replacing these will cause you to lose any existing sites & setup so tread carefully.
I faced the same problem on Windows 10, resolved it with ljsg's suggestion.
In Console with elevated privileges (Run as Admin):
cd %SYSTEMROOT%\System32\Inetsrv\Config
copy *.clean.install *.
ren *.config *.back
ren *.config.clean *.
#powershell -Command "Disable-WindowsOptionalFeature -Online –All -FeatureName #('IIS-ApplicationDevelopment','IIS-ApplicationInit','IIS-ASP','IIS-ASPNET','IIS-ASPNET45','IIS-BasicAuthentication','IIS-CertProvider','IIS-CGI','IIS-ClientCertificateMappingAuthentication','IIS-CommonHttpFeatures','IIS-DefaultDocument','IIS-DigestAuthentication','IIS-DirectoryBrowsing','IIS-FTPServer','IIS-FTPSvc','IIS-HealthAndDiagnostics','IIS-HostableWebCore','IIS-HttpCompressionDynamic','IIS-HttpCompressionStatic','IIS-HttpErrors','IIS-HttpLogging','IIS-HttpRedirect','IIS-HttpTracing','IIS-IIS6ManagementCompatibility','IIS-IISCertificateMappingAuthentication','IIS-IPSecurity','IIS-ISAPIExtensions','IIS-ISAPIFilter','IIS-LegacyScripts','IIS-LegacySnapIn','IIS-LoggingLibraries','IIS-ManagementConsole','IIS-ManagementScriptingTools','IIS-ManagementService','IIS-Metabase','IIS-NetFxExtensibility','IIS-NetFxExtensibility45','IIS-Performance','IIS-RequestFiltering','IIS-RequestMonitor','IIS-Security','IIS-ServerSideIncludes','IIS-StaticContent','IIS-URLAuthorization','IIS-WebDAV','IIS-WebServer','IIS-WebServerManagementTools','IIS-WebServerRole','IIS-WebSockets','IIS-WindowsAuthentication','IIS-WMICompatibility','WCF-HTTP-Activation','WCF-HTTP-Activation45','WCF-NonHTTP-Activation','WCF-Pipe-Activation45','WCF-Services45','WCF-TCP-Activation45','WCF-TCP-PortSharing45','WAS-ConfigurationAPI','WAS-NetFxEnvironment','WAS-ProcessModel','WAS-WindowsActivationService')"
Then reboot, and follow with:
#powershell -Command "Enable-WindowsOptionalFeature -Online –All -FeatureName #('IIS-ApplicationDevelopment','IIS-ApplicationInit','IIS-ASP','IIS-ASPNET','IIS-ASPNET45','IIS-BasicAuthentication','IIS-CertProvider','IIS-CGI','IIS-ClientCertificateMappingAuthentication','IIS-CommonHttpFeatures','IIS-DefaultDocument','IIS-DigestAuthentication','IIS-DirectoryBrowsing','IIS-FTPServer','IIS-FTPSvc','IIS-HealthAndDiagnostics','IIS-HostableWebCore','IIS-HttpCompressionDynamic','IIS-HttpCompressionStatic','IIS-HttpErrors','IIS-HttpLogging','IIS-HttpRedirect','IIS-HttpTracing','IIS-IIS6ManagementCompatibility','IIS-IISCertificateMappingAuthentication','IIS-IPSecurity','IIS-ISAPIExtensions','IIS-ISAPIFilter','IIS-LegacyScripts','IIS-LegacySnapIn','IIS-LoggingLibraries','IIS-ManagementConsole','IIS-ManagementScriptingTools','IIS-ManagementService','IIS-Metabase','IIS-NetFxExtensibility','IIS-NetFxExtensibility45','IIS-Performance','IIS-RequestFiltering','IIS-RequestMonitor','IIS-Security','IIS-ServerSideIncludes','IIS-StaticContent','IIS-URLAuthorization','IIS-WebDAV','IIS-WebServer','IIS-WebServerManagementTools','IIS-WebServerRole','IIS-WebSockets','IIS-WindowsAuthentication','IIS-WMICompatibility','WCF-HTTP-Activation','WCF-HTTP-Activation45','WCF-NonHTTP-Activation','WCF-Pipe-Activation45','WCF-Services45','WCF-TCP-Activation45','WCF-TCP-PortSharing45','WAS-ConfigurationAPI','WAS-NetFxEnvironment','WAS-ProcessModel','WAS-WindowsActivationService')"
..of course features to install should be adjusted as needed.
I have got the error and solved by working as like above solutions But work with third one also.
"Internet Information Services" (IIS)
"Windows Process Activation Service" (WAS)
"Internet Information Services Hostable WebCore"
Third Windows feature - that need to uninstall/install:

Why don't QLocalSocket/Server connections work when one process was invoked by an NSIS installer?

I have an NSIS installer that installs my Qt application. At the end of the install process, the installer gives the user the option to launch the application immediately.
My application uses QLocalSocket/QLocalServer to talk to other local instances of the application. (They talk to each other basically just to ensure that there's only one instance of the app running at a time.) However, on Vista, if one of the instances was started up by the installer, then other instances cannot talk to that instance unless they were also started by the installer (or uninstaller, interestingly).
The NSIS installer launches the app with the Exec command. The client tries to connect to the server through QLocalSocket::connectToServer, which fails with the error "QLocalSocket::connectToServer: Unknown error 5".
Can anyone explain this? What's the best way to work around it?
If 5 is a windows error code, it would mean access denied. Is there a way for you to change the security on this server (You would need to access the native pipe handle)?
The finish page run option has more issues than just this, the new process gets the wrong HKCU and user profile etc.
I would recommend just disabling the run checkbox on the finish page. (This issue goes all the way back to win2000 when RunAs was added)
If you really really want this run checkbox, you can use the UAC plugin, it will allow you to start a child process as the "correct" user.
Finally figured this out. The installer was running as admin (the install script said "RequestExecutionLevel admin"), and apparently it launched my app with those elevated permissions, which meant that other instances of my app running with user-level permissions couldn't connect to it. QLocalSocket/Server uses named pipes on windows, so I figure this is a windows security feature. I'm planning to work around this by using the UAC NSIS plugin, which I believe lets you run a process with user-level permissions.

Replicate IIS setup from one machine to another

Looked for an answer to this and didn't see it.
This is for IIS 6.0 / Windows Server 2003.
I'm working with an extremely large ASP/ASP.NET application and I'm trying to get my development environment to match my team members environment. This process is basically trial and error: get an error, go into IIS, make a change, hope the error is fixed. Ugh. I'm hoping to find a way to replicate a set of IIS directories and their configurations on one machine onto my machine.
I did find a script that will iterate through and give me a list of all virtual directories on a machine. It helped, but not a lot since I still have to go in and set up all those virtual directories (I think there are like 20 of them ballpark). The whole process is complicated by the fact that we're mixing ASP and ASP.NET applications in the same application which spans many solutions and projects. Getting the whole thing up and going seems like way too much work but I've never heard of a real solution to this.
Would Powershell be helpful here?
You should export and import IIS metabase.
These might help:
IIS Settings Replication
IIS Metabase Backup and Restore
Fortunately, in IIS7, ASP.NET config is integrated with IIS config so the job is done by copying Web.config.
Here's Microsofts' documentation for iiscnfg. iiscnfg documentation
When I ran it the first time, I got an error that said "This script does not work with WScript." If that happens to you:
1. Click OK.
2. At the "Would you like to register Cscript as your default host for VBscript?" click Yes.
3. At "Successfully registered Cscript" click OK.
4. Run the command again

Resources