Two things I learned tonight moving an ASP.NET site from IIS6 to IIS7

Tonight I moved moved an ASP.NET site from IIS6 to IIS7. Things seemed broken pretty badly at first, and I wondered if I was making a mistake to leave the comfort of IIS6. However, it turned out to be minor changes to the web.config. I'm sure they're already well known and well documented, but I figured I would scribble them down in case I ever need to do it again.

1. Remove the built-in Membership, Role and Profile providers

If you are configuring your own Membership, Role or Profile providers with your own database connection string, make sure you remove the built-in ones.or you may get an exception about not being able to connect to "LocalSqlServer".  Which is the connection string used in machine.config for the stock providers. This did not happen under IIS6. So it turns out the bolded lines become very important under IIS7.

<membership defaultProvider="MembershipSqlProvider"...>
  <providers>
    <remove name="AspNetSqlMembershipProvider"/>
    <add name="MembershipSqlProvider"
           :
           connectionStringName="MyDatabaseConnection"/>
  </providers>
</membership>

<roleManager defaultProvider="RoleManagerSqlProvider"...>
  <providers>
    <remove name="AspNetSqlRoleProvider"/>
    <add name="RoleManagerSqlProvider"
           :
           connectionStringName="MyDatabaseConnection"/>
  </providers>
</roleManager>

<profile defaultProvider="SqlProfileProvider">
  <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="SqlProfileProvider"
           :
           connectionStringName="MyDatabaseConnection"/>
  </providers>
</profile>

2. Move your Modules and Handlers to the <system.webServer> section

This one took me a while to figure out, but it shouldn't have. I had a custom module that was redirecting to secure pages when necessary, and it was not firing under IIS7. So I instrumented it up with log statements, and still nothing. Hmm. A quick search turned up Rick Strahl's post on this.

<configuration>
 
  <system.web>
    <httpModules>
      MODULES DON'T GO HERE ANYMORE
    </httpModules>
    <httpHandlers>
      HANDLERS DON'T GO HERE ANYMORE
    </httpHandlers>
  </system.web>

  <system.webServer>
    <modules>
       FOR IIS7, MODULES GO HERE NOW
    </modules>
    <handlers>
       FOR IIS7 HANDLERS GO HERE NOW
    </handlers>
  </system.webServer>
 
<configuration>

No Comments