Alvin
Alvin

Reputation: 11

How to remove/hide the default page (default.aspx or index.aspx) from the domain name URL with ASP.NET 3.5

My requirement is as our SEO professional suggests www.example.com/index.aspx
should be loaded as www.example.com for google index Canonical Issue

I also like to mention because of shared server we can’t access IIS server, and support people are not much cooperative.

I tried following code in global.asax. Index.aspx is a default page for the site so it is throwing error: "500 - Internal Server Error."

void Application_BeginRequest(object sender, EventArgs e)
{

    HttpContext incoming = HttpContext.Current;

    string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
    if (oldpath.Contains("index.aspx") == true)
    {
    HttpContext.Current.RewritePath("http://www.example.com", false);
    }
}

//Also tried following 
void Application_BeginRequest(object sender, EventArgs e)
{

    HttpContext incoming = HttpContext.Current;

    string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
    if (oldpath.Contains("index.aspx") == true)
    {
        Response.Redirect"http://www.example.com"
    }
}

Upvotes: 0

Views: 1714

Answers (1)

Xedecimal
Xedecimal

Reputation: 3223

You may want to wrap this with

<script language="c#" runat="server">
</script>

Upvotes: 0

Related Questions