DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

Resolve "Redundant Hostnames" issue using ASP.NET

By Ashok Nalam on 19 Sep 2015 | Category: ASP.NET | Tagged: global.asax ASP.NET error 
This snippet show how to resolve "Redundant Hostnames" issue using ASP.NET.
  Discuss Add Comment   |  
Add rating Rate this resource   

Introduction

Today I have recevied a notification in Google Analytics saying "Redundant Hostnames" found for your property dotnetmirror.com. Redundant Hostnames means, search engine considers URL's with http://dotnetmirror.com and http://www.dotnetmirror.com (with out WWW and with WWW) differently.

Redundant Names Notification from Analytics

How to Resolve:

To resolve this issue add below code to Global.asax in Application_BeginRequest method.

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://dotnetmirror.com"))
        {
            HttpContext.Current.Response.Status = "301 Redirect";
            HttpContext.Current.Response.AddHeader("Location",HttpContext.Current.Request.Url.AbsoluteUri.
			ToString().ToLower().Replace("http://dotnetmirror.com", "http://www.dotnetmirror.com"));
            HttpContext.Current.Response.End();
        }
	

From the above code we are replacing http://dotnetmirror.com with http://www.dotnetmirror.com when the request contains http://dotnetmirror.com.

  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 6963  (Expert)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.