IIS 6 and Apache on the same server and port

This has been written about before, but I just ran into it, and hopefully I can save someone a headache.

Apache Feather 

I installed Apache on my dedicated server, which has 9 IP addresses. Since all my sites have a dedicated IP address, I figured I would just configure Apache to listen on some IP's, and IIS listen on the others. They both would listen on port 80. I configured it correctly, only to find out that Apache wouldn't start.

It turns out that IIS hogs port 80 on all IP addresses, whether IIS is configured to listen on them or not. Microsoft has a good knowledge base article on the subject, and of course it's by design so it's not going away.

The only thing to remember is that the instructions are for specifying the IP addresses that IIS should listen on. For some reason, I was thinking the opposite initially, which obviously caused some frustration.

Like this post? Please share it!

See a mistake? Edit this post!

Serving your ASP.NET .aspx pages with .html

Many SEO experts believe that Google prefers pages that end with the "html" extension. I'm guessing it has to do with the fact that static content is favored, because it is less commonly spammed. Even if Google doesn't actually look at the extension, you certainly won't be penalized for using the "html" extension.

carrying www

To support a custom extension, my first thought was to put the following code in my web.config:

<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />

This wouldn't be a bad way to do it, if not for the fact that ReSharper doesn't like code for non-aspx files. I'm speculating that you may run into problems with other Visual Studio add-ins.

The alternative to use Server.Transfer by intercepting the requests, and transferring them to the correct page for processing.

Here is a basic example of an IHttpModule that will do the rewriting. I offer no guarantees with this code. In fact, I don't use it anywhere in production (we use a full blown rewriter solution):

public class HtmlUrlRewriter : IHttpModule
  private HttpApplication _context;
  private void context_BeginRequest(object sender, EventArgs e)
      string path;
      path = _context.Request.Path;
      if (path.EndsWith("html", true, CultureInfo.CurrentCulture))
  public static Uri RewriteUri(Uri uri)
      UriBuilder newUri;
      newUri = new UriBuilder(uri);
      newUri.Path = newUri.Path.Replace(".html", ".aspx");
      return newUri.Uri;
  #region IHttpModule Members
  public void Init(HttpApplication context)
      _context = context;
      context.BeginRequest += context_BeginRequest;
  public void Dispose()

Of course you'll probably have other types of requests that you are going to be rewriting, so I recommend coming up with a URL rewriter framework, or use one of the third party options that are available.

One last note. Before IIS will allow ASP.NET to handle the processing of html files, you need to add an application extension mapping. More information about configuring IIS mappings is available here.

Obishawn also has some more information about URL rewriting and postbacks on his blog.

Like this post? Please share it!

See a mistake? Edit this post!

Working with content areas in code behind

In my master page, I have a ContentPlaceHolder defined:


In the page, I have the content defined:

<asp:Content runat="server" ID="conTrackingScripts" ContentPlaceHolderID="AfterScripts">
    <!-- Blah -->

Unfortunately, this code does not work:

conTrackingScripts.Visible = false;

The error given is "The name 'conTrackingScripts' does not exist in the current context. A quick Google search shows that many others have had the same issue. The solution is to use the following code instead:

(Master as MasterPage).FindControl("AfterScripts").Visible = false;

Substitute the name of your master page for "MasterPage", and the name of your ContentPlaceHolder for "AfterScripts" in the above code

It appears that you cannot edit properties on the content, you have to edit the ContentPlaceHolder directly.

Like this post? Please share it!

See a mistake? Edit this post!

Jason Young I'm Jason Young, software engineer. This blog contains my opinions, of which my employer - Microsoft - may not share.

@ytechieGitHubLinkedInStack OverflowPersonal VLOG