Friday, June 24, 2011

want to quickly set custom errors in IIS 7 via command for several errors?

here is how:

for %%i in (401 403 404 405 406 412 500 501 502) do c:\Windows\System32\inetsrv\appcmd.exe set config /section:httpErrors /-[statusCode='%%i'].prefixLanguageFilePath /[statusCode='%%i'].path:"/vdir1/custom_error_file.htm" /[statusCode='%%i'].responseMode:Redirect /commit:apphost


this will set redirect for all the error codes listed in () above. If the path ever changes, run the same command , replace part in green with new URL to point to.

Wednesday, June 15, 2011

why a 401 response on 2008 IIS 7 webserver?

When you used adsutil.vbs or IIS 6 scripting tools in general on 2008 server, the RESULT is a broken IIS vdir or worse.
adsutil.vbs is a tool for IIS 6 on 2003 server.
appcmd.exe is the correct tool for manging IIS on 2008

if you use it or any IIS 6.0 scripting tools to create a vdir on 2008's IIS 7, you will get a 401 server response.the reason for this is b/c in the main config C:\Windows\System32\inetsrv\config\applicationHost.config, something like this gets added:
%computername%" />
It creates anonymous access for an account that does not exist.only IUSR exists on 2008 unless you have FTP running!
so resolution is to remove the entry and add it back via appcmd.exe tool OR to install FTP. when you install FTP, the account will be created.