Enable Handler Mappings

by Vaughn Anderson 23. September 2011 10:41

I recently ran into a situation where the Handler Mappings on my website were disabled.  I figured it would be a simple solution of right clicking on the the mapping I needed and enabling it.  Right clicking though revealed there was no “enable” feature or anything remotely close to it.  Therefore, I had to dig around (read that as randomly click on stuff until I found what worked because Google wasn’t helping me) and found the solution.  I went to the Handler Mapping that was disabled, right clicked on it and then selected Edit Feature Permissions…


Read permissions were already selected, so I also selected Script.  After I did this, it enabled the Handler Mappings that were disabled





URL Rewrite And A Sorry Server

by Vaughn Anderson 2. August 2011 10:00

We have our load balancers configured if all the servers in a VIP fail, then they redirect all traffic to a sorry server.  This seemed easy enough, but then when we tested it, we found some weird results.  For example, if someone goes to http://www.site.com and that request hits the sorry server, things work without any issues.  The sorry server will display the under maintenance page since the user was trying to access the default document on the web site.

What if a user has a login page bookmarked and it looks something like this – https://site.com/login.aspx?ID=725?  That request will not be captured by the default document.  Initially, I thought I could just make my “Under Maintenance” page my default 404 error page displaying the under maintenance banner, but that’s bad hosting.  The proper response for something that is temporarily unavailable is a 307.  Therefore, I needed a way to redirect all traffic to the maintenance page, but give a 307 response.  Plus, it must be a lightweight solution since the sorry server is a VM that does not have that much processing power.  URL Rewrite to the rescue.

Open URL Rewrite in IIS and create a new Blank Rule.  I called mine “Redirect all.”  Here’s a picture of my configuration and the code if you want to add it directly to your web.config.  Then I will explain why I configured it this way.


Web.config code:

    <rule name="Redirect all" enabled="true" stopProcessing="true">
        <match url="(.*)" negate="false" />
        <action type="Redirect" url="/index.htm" redirectType="Temporary" />
            <add input="{REQUEST_FILENAME}" pattern="index\.htm" negate="true" />

So let’s break this down section by section.

  • In the Match URL area, I want to capture all traffic, hence the (.*) pattern.
  • For the Conditions, I wanted anything that did not match the default document of index.htm to flag a condition. This is because the only page that works properly is the default document.
  • I didn’t have any server variables.
  • For the Action, I wanted to redirect all traffic caught in the “Conditions” section and redirect it to the default document.  Since I have many different URLs feeding to this rule, I just left the generic relative path of /index.htm.


IIS | URL Rewrite

SEO Compliance

by Vaughn Anderson 11. July 2011 15:06

Search engine optimization (SEO) is a pain, but if you want to maintain your high rankings as a company, you have to comply by the sometimes confusing standards.  We recently updated our company web site and had to do several things to make sure the new web site did not drop our search engine rankings.

The first item I had to fix was all of the old common pages needed to have a 301 redirect pointing to the new page.  Since our old site was written in ASP, this was not as simple as adding some redirects to the web.config and being done.  I had to create the redirect rule for each of the old pages and add them to our web site.  Obviously, I did not do this for every old page, just the important ones.  To accomplish the redirect  I created a file with the exact same path and file name as the old file.  Then, I added the following code:

<%@ Language=VBScript %>
Response.Status="301 Moved Permanently"
Response.AddHeader "Location",”http://www.site.com/newpage.aspx”

Basically the only litem you need to change is the “http://www.site.com/newpage.aspx” entry to point to your new page.

Once we had fixed the old pages that would have resulted in a 404 error, we had to fix some other common issues.  To do this, I used URL Rewrite, a free add-on to IIS 7.  You can use the GUI for URL Rewrite in the IIS 7 interface, but you can also just copy rules directly into your web.config file.  All you need to do is create a section called <rewrite> in the <system.webServer> section.  Then, each rule starts with a <rule name=”…> section.  I am going to be giving my examples through additions to the web.config file and not using the GUI.

Scenario: Web crawler sees http://site.com different from http://www.site.com
Solution: Rewrite the URL by using the following rule

<rule name="WWW redirect" enabled="true" stopProcessing="true">
    <match url="(.*)" />
        <add input="{HTTP_HOST}" pattern="^www\.site\.com$" negate="true" />
    <action type="Redirect" url="http://www.site.com/{R:1}" />

Scenario: SEO and the default document do not agree on the way to display text.  For instance, http://www.site.com and http://www.site.com/default.aspx are the same page, but SEO results do not like that.
Solution: Rewrite the URL so it either always displays the /default.aspx or never displays it.  I opted to have it never show just because I think it looks cleaner.

<rule name="Default Document URL Rewrite" enabled="true" stopProcessing="true">
    <match url="(.*?)/?Default\.aspx$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Redirect" url="{R:1}/" />

Scenario: SEO sees http://www.site.com different from http://www.site.com/
Solution: Rewrite the URL so it always includes the trailing slash.

<rule name="Trailing Slash" stopProcessing="true">
    <match url="(.*[^/])$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{URL}" pattern="WebResource.axd" negate="true" />
    <action type="Redirect" url="{R:1}/" />

Scenario: SEO sees http://WwW.SiTe.CoM different from http://www.site.com|
Solution: Eliminate uppercase letters in your URLs

<rule name="Convert to lower case" stopProcessing="true">
     <match url=".*[A-Z].*" ignoreCase="false" />
     <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />

Hope that helps.  Also, the rules are processed in the way they are processed in the web.config file, top to bottom, so arrange the rules in the order you want them processed.


IIS | SEO | URL Rewrite

MS Deploy–almost too good

by Vaughn Anderson 17. April 2011 15:10

I am migrating a IIS 6 server to IIS 7 and used the following command in MS Deploy:

msdeploy -verb:sync -source:webserver60 -dest:webserver60,computername=web04 >msdeploy.log

This makes an exact copy of my IIS 6 configuration including the Application Pools and deploys it on my IIS 7 server.  Well, it does it a little too good.  When I browsed to the sites to verify that they worked, I kept getting 401.2 – Unauthorized errors.  When I checked my Anonymous Authentication settings, I saw this:

In my mind that looked right, but under closer examination, it is wrong.  IIS 7 users the user “IUSR” for anonymous authentication.  To fix it, press the Set button and the following window will appear:

Type in the user “IUSR” without the quotes and leave the password area blank.  It will automatically inherit the appropriate password because it is a built-in account (for more info, go here).  This should correct the authentication issue you are experiencing.


IIS | IIS6 | IIS7 | MSDeploy

Change Website Path in IIS 6

by Vaughn Anderson 11. April 2011 16:45

We are almost done phasing out our IIS 6 servers, but we have a couple left in production and a developer asked me if it’s possible to change the web site path in IIS 6 via command line so he could script out deployments.  I’ve covered how to do this in IIS 7 in this article, but since appcmd is IIS 7 only, I had to figure out how to do it using other tools. After some research, I found you can run:

iisweb /create C:\Path\subfolder "SiteName" /d hostheader.domain.com

This will overwrite the existing site to change the path, but reset the application pool to the default app pool.  One of the weaknesses of IIS 6 is it allows you to set different versions of .net in the same application pool, but then the application pool crashes once the second version tries to run.  So this wasn’t the solution.  Long story short, I opted just to alter the Metabase directly using the following command:

ADSUTIL.VBS set w3svc/111111/root/path “C:\Path\subfolder”

This changed path of site 111111 to C:\Path\subfolder, but kept the rest of the settings for the web site, including the application pool, IP bindings, host header settings, and virtual directory settings.


Command | IIS | IIS6

Web Deploy Refresh

by Vaughn Anderson 11. April 2011 15:18

Microsoft released an update to Web Deploy (also know as MS Deploy) last week.  Here is the link to download it - http://blogs.iis.net/msdeploy/archive/2011/04/05/announcing-web-deploy-2-0-refresh.aspx.  For me the biggest improvement is the improved error messages.  Some of the old ones were vague or missing entirely.


IIS | IIS6 | IIS7 | MSDeploy

URL Rewrite Exclusions

by Vaughn Anderson 21. March 2011 11:29

We are reviewing our current setup in IIS at work.  Our company site is still written in ASP so we were doing the redirect to www.domain.com through a 302 redirect in IIS by having a site dedicated to doing the redirect.  This works ok, but I prefer to not have two sites in IIS when one site will do.  Therefore, I downloaded URL Rewrite and configured it handle the redirect.  This was easy. Here’s a picture of what I configured (click on image for full size picture).


The highlights are as follows:
Match URL Section
Requested URL: – Matches the Pattern
Using: – Regular Expressions
Pattern: – (.*)
Input – {HTTP_HOST}
Type – Does Not Match the Pattern
Pattern - ^www\.domain\.com$
Action type – Redirect
Action Properties (Redirect URL)
Append query string – checked
Redirect type: – Found (302)

The problem came when we needed to exclude secure.domain.com.  Since the redirect was redirecting all traffic that did not match the expression www.domain.com, if you came in through secure.domain.com, you would get redirected to www.domain.com. This required us to add a new rule.  Here are the highlights for this rule.


The only two changes were in the Conditions area, we wanted to MATCH the pattern and then in the action, set the action type to None and then check the box to stop processing all subsequent rules.


Lastly, set the order of the rules so the secure.domain.com rule is first and the redirect rule is second.  This will allow the redirect rule to be processed second.  When the secure.domain.com rule process first, it enables it to exclude the redirect rule from processing.



IIS | IIS7 | URL Rewrite

Invisible directories in IIS 6

by Vaughn Anderson 9. March 2011 10:56

Have you ever seen items show up in the IIS 6 Manager that are not listed in the folder?  And I know what you’re thinking.  No, these are not virtual directories.  Here, take a look.

In particular, look at the directories labeled v1.7.8.5_xxx, v1.8.12.2, v1.8.12.3.  You will see they are not listed in the folder on the right which is the root folder of that directory (honest, I swear).  So where are those entries coming from?  Go to Start – Programs – IIS Resources – Metabase Explorer – Metabase Explorer for the answer.


Looking in IIS Metabase Explorer, drill down to the site ID – root and then look at all the subdirectories.  These are all the applications running in this web site.  Or in my case, all the applications and some former applications.  The interesting thing for me is there are even more former applications that are showing up in the Metabase than are in IIS Admin.  I’m not sure why some are showing in one place but not the other.  When I delete all the extra entries out of the Metabase, they disappear from the IIS Admin though.



Web Farm Framework restarting w3svc

by Vaughn Anderson 27. February 2011 16:51

I have the sites in our development lab syncing with the Microsoft Web Farm Framework but I noticed every 30 seconds that the w3svc service was stopping and then starting on my secondary server.  This is not good since all our web sites are .Net and the spool up time on the new application pools would have killed us.  A quick check of my settings revealed I left the check box to “Take server offline while syncing applications” checked.
Save yourself the headache and turn this off or change your synchronization interval so your other servers don’t restart the w3svc every 30 seconds.


IIS | Web Farm Framework

Change the path of a site in IIS using appcmd

by Vaughn Anderson 16. February 2011 16:36

We need to change the path to our web sites often because we release new versions of our code almost weekly.  I figured it would be pretty easy to script this out, but I found this was not as simple as it seemed.  I wanted to use the following command to do it - appcmd set site, but that failed.  Digging in, I found when you run “appcmd list site "Site" /config” you will see (circled in red) that the path to the site is actually a virtual directory.


From there, I used the appcmd set vdir command to change the directory that my site points to.  Here is the command I used:

appcmd set vdir "Test1/" -physicalPath:"C:\inetpub\Websites\Test"

You will notice that I had to add the “/” after the site name.  This is very important because you are changing the attribute <virtualDirectory path="/" physicalPath="C:\inetpub\Websites\Test1" />.

Note, that this can also be used to change the path to a virtual direcotry.  You just have to use the following syntax:

appcmd set vdir "Test1/ExistingDirectory/" -physicalPath:"C:\Path\To\Directory"

For this, just put the site name followed by the virtual directory you are altering.  Remember though this does not add the directory, it will only modify the path to the existing directory.


appcmd | IIS

About the author

Just a guy trying to record what he does in IIS and Hyper-V so others might benefit.

Month List