Redirect 301 in global.asax

Topics: ASP.NET 2.0, Business Logic Layer, Controls
Sep 29, 2012 at 11:25 AM

I'm trying to redirect my old address to new address of my site in BlogEngine.Net... i want to delete subdirectory /blogengine by my site...  now is http://www.informarea.it/blogengine/ i wanto to change in http://www.informarea.it/ . Naturally i have also much articles that have url with word /blogengine....

this is my code but don't work.... can you help me someone pleasee....????

    void Application_BeginRequest(object source, EventArgs e)
    {

	HttpApplication app = (HttpApplication)source;

         string url = (app.Request.Url.Scheme + "://" + app.Request.Url.Authority + app.Request.Url.AbsolutePath);
            bool redirect = false; 
            
           if (app.Request.Url.ToString().ToLower().Contains("http://www.informarea.it/blogengine/"))
 		
            {
                redirect = true;                 
                url=app.Request.Url.ToString().ToLower().Replace("http:///www.informarea.it/blogengine/","http://www.informarea.it/blogengine/");
           
            } 
 
           if (redirect)
	   {
              Redirect301(app, url + app.Request.Url.Query);
	   }
	  else 
	  {
	   
	       HttpContext context = app.Context;
        
        	// Attempt to perform first request initialization
               FirstRequestInitialization.Initialize(context);      
	  }

         
        }
 
        private void Redirect301(HttpApplication app, string location)
        {
            // set status to 301 - Perm Redirect
            app.Response.StatusCode = 301;
            app.Response.Status = "301 Moved Permanently";
            app.Response.StatusDescription = "Moved Permanently";
            app.Response.AddHeader("Location", location);
            app.Response.End();
        }       
    

Oct 23, 2012 at 5:37 PM

Hi 

i don.'t have still solved redirect permanently by my subdirectory to root someone have founded or know solutìon?

thanks

fabry