This project is read-only.

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 i wanto to change in . 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(""))
                redirect = true;                 
           if (redirect)
              Redirect301(app, url + app.Request.Url.Query);
	       HttpContext context = app.Context;
        	// Attempt to perform first request initialization

        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);

Oct 23, 2012 at 5:37 PM


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