Reputation: 11
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
Reputation: 3223
You may want to wrap this with
<script language="c#" runat="server">
</script>
Upvotes: 0