Frederik Vig – ASP.NET developer

Follow me

Archive for July 2010

EPiCode.Extensions and ambiguous reference

On new projects where I use EPiCode.Extensions I always register the namespace EPiCode.Extensions in my web.config – that way I can use the extension methods in my .aspx and .ascx files without needing to register EPiCode.Extensions in every file.

...
      <namespaces>
        ...
        <add namespace="EPiCode.Extensions" />     
      </namespaces>
    </pages>
...

Sometimes this can cause some problems when you have other extension methods with the same method signature.

Ambiguous call between two extension methods with the same signature

In this case it was with EPiServer Composer. To fix it I created a simple web.config file that I placed inside the Dropit\Plugin\Extension folder.

Here’s the code.

<?xml version="1.0"?>
<configuration>
  <system.web>
      <pages>
          <namespaces>
              <remove namespace="EPiCode.Extensions" />
          </namespaces>
      </pages>
  </system.web>
</configuration>

You can also use the location element of your main web.config file instead.

<location path="dropit">
        <system.web>
            <pages>
                <namespaces>
                    <remove namespace="EPiCode.Extensions" />
                </namespaces>
            </pages>
        </system.web>
    </location>

And that’s it! This will also work for all the sub directories as well.

On a side-note: I’ve been adding a lot of new extension methods lately to the project. I’ve listed them on the project’s wiki-page. Go check them out!

Specify a canonical domain name for your site with IIS 7

When setting up new sites in IIS you specify which host names map to your site. Usually this is at least two: www.example.com and example.com, sometimes even more. One great new addition to IIS 7 is the URL Rewriting extension. This allows you to setup a few rules for your URLs.

Let’s start by downloading and installing the URL Rewrite extension. The official IIS site has a download section with some very cool extension that I recommend you check out when you have the time. For now we only need the URL Rewrite extension. This will launch the Web Platform Installer, click Install and Accept. You should now see a new module in IIS.

URL Rewrite extension in IIS 7

To setup the rule we need for our canonical domain, just click the Add Rule(s) link and and under Search Engine Optimization (SEO) section choose Canonical domain name. Select a primary host name and you’re done!

Choose primary host name during Add rule with IIS URL Rewrite

What this does is redirect all traffic going to www.frederikvig.com to frederikvig.com, www.frederikvig.com/news to frederikvig.com/news etc, with a 301 (permanent redirect).

The reason this is important for SEO purposes is that search engines treat all URLs differently, so when you have two or more URLs all pointing to the same content your search ranking will suffer. Fortunately we have fixed this now with this rule, next time Google or some other search engine visits your site it will update it’s indexes, making all links point to the same domain name.

There are a lot of other great enhancements (Enforce lowercase URLs, User Friendly URLs etc) that I recommend checking out. Here are a few articles to get you started.

© Copyright Frederik Vig. Based on Fluid Blue theme