Page view counter

301 permanent redirect

Rate It (1)

Last post 08-07-2008 9:40 PM by docluv. 4 replies.

Sort Posts:

  • 301 permanent redirect

    03-07-2004, 4:00 AM
    • Loading...
    • geebee2
    • Joined on 01-05-2004, 5:27 PM
    • Gloucester, UK
    • Posts 49
    • Points 245
    Thought I would share this, not because it is difficult, but because of a pitfall that I fell into.

    Also, I couldn't find any discussion of coding a 301 redirect with ASP.net, and it is a common task for keeping search engines like Google happy, etc.

    The point is that

    Response.StatusCode = 301;
    Response.Redirect( s ); // No good !!

    does not work. I am not 100% sure why, but presumably Redirect sets the status code intenally.

    What you need instead is

    Response.StatusCode = 301;
    Response.RedirectLocation = s;
    George

    Design your database-driven web-site online at qaaz.com
  • Re: 301 permanent redirect

    03-21-2004, 11:41 AM
    • Loading...
    • tasmisr
    • Joined on 11-19-2002, 8:58 AM
    • Auburn Hills, Michigan
    • Posts 56
    • Points 242
    thanks geebee2!! time to put this into test...
    Working on: MCAD

    'We're all one hand'

    -T
  • Re: 301 permanent redirect

    03-21-2004, 4:15 PM
    • Loading...
    • geebee2
    • Joined on 01-05-2004, 5:27 PM
    • Gloucester, UK
    • Posts 49
    • Points 245
    I hope you found it useful - post again here if any questions arise.
    Best regards,
    George

    Design your database-driven web-site online at qaaz.com
  • Re: 301 permanent redirect

    08-07-2008, 11:08 AM
    • Loading...
    • Sojan80
    • Joined on 10-28-2004, 7:59 AM
    • WI
    • Posts 185
    • Points 177

     I have found that the following method also works:

    private void Page_Load(object sender, EventArgs e)
    {
    Response.StatusCode = 301;
    Response.AddHeader("Location", "your url here");
    Response.Write("<html><body>Page moved permanently to <a href=\"your url here\">New</a></body></html>");
    Response.End();
    }
     
  • Re: 301 permanent redirect

    08-07-2008, 9:40 PM
    • Loading...
    • docluv
    • Joined on 06-29-2002, 7:16 PM
    • Willow Spring NC
    • Posts 1,733
    • Points 10,515
    • TrustedFriends-MVPs
Page 1 of 1 (5 items)