Fix canonical redirect issue on ASP NET in a shared host (Rackspacecloud)

by Xavier Comments: 2

I delivered an seo optimization project a few days ago and one of the issues that needed to be fixed was the canonical redirection issue. For those of you who don’t know exactly what it is (but probably are here because you want to implement a fix for it), let me explain.

– You have a site, i.e. www.xaviermorera.com
– You have a page: www.xaviermorera.com/mypage.html
– If you type xaviermorera.com/mypage.html, the page still displays but the “www” is not added

That is canonical redirection, both urls work and the “www” is not added. So why it is a problem? Because Google or other search engines think it is actually two pages instead of one. Which it is funny because you have canonical redirection on one end and page canibalization on the other!

So, how to solve?
– One (expensive) option is to install an isapi filter on your IIS
– Or have a dedicated host and configure via the IIS manager

But none of them work in a shared host!

So, here is the solution you’ve been waiting for: (this post is specific for ASP NET)

In the Application_BeginRequest in your global.asax, just type a code to look for the “www”, and if it is missing simply add it. The following code will do the trick:

if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().StartsWith(“http://xaviermorera”))
{
string newUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Replace(“http://xaviermorera”, “http://www.xaviermorera”);
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”, newUrl);
}

I did it for http://www.softwaresynergy.com and it worked fine 🙂

Setting your default page in ASP NET

by Xavier Comments: 0

Let’s say you host your site in www.godaddy.com or Mosso or someplace else. You don’t have access to IIS and you need to set the default start page in your ASP NET application.

If you are working with ASP.NET just do it by setting it in the web.config:

<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                    <add value=”yourstartpage.aspx” />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

If you are using FormsAuthentication do the following to set the default page
<authentication mode=”Forms”>
<forms name=”.COOKIENAME”
loginUrl=”YourLoginPage.aspx”
defaultUrl=”YourDefaultPage.aspx”
protection=”All”
timeout=”30″
path=”/”> 
</forms>
</authentication>

ASP.NET v2.0.50727 missing in Web Services Extensions in IIS Manager

by Xavier Comments: 0

If you are installing SharePoint and you bump into the issue that ASP Net v2.0 is not in the Web Server Extensions, then you could do a research and find out that you installed a newer version of the framework, namely SP1.

According to Microsoft, you need to uninstall SP1, install .Net 2.0 and then move from there: http://support.microsoft.com/default.aspx/KB/906894

Sounds a bit dumb

But don’t worry, go to
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> or C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727> for 64 bit

Type aspnet_regiis.exe –i

A lot easier!