This project is read-only.

Redirecting extension less urls

Topics: Controls
Oct 18, 2011 at 3:02 AM
Edited Oct 24, 2011 at 6:33 PM

I am using the SEO Rediretor Extension.


I modified to code  to look at the start of the url


Old URL: http://localhost:54512/javascript/

New URL: http://localhost:54512/post/


foreach (DataRow row in table.Rows)
                    var oldPrefix = row["OldUrl"].ToString();
                    if (context.Request.Url.AbsoluteUri.StartsWith(oldPrefix, StringComparison.OrdinalIgnoreCase))
                        newUrlstart = row["NewUrl"].ToString() + context.Request.Url.AbsoluteUri.Substring(oldPrefix.Length) + (newUrlstart.TrimEnd('/'));

                        newUrl = newUrlstart + ".aspx";



But it adds an "/"  charter before the .aspx in the url


So I get this:



where is this "/" is coming from?


If I take out the "/" in the New or Old URL it moves it from the end to the front like this



Thanks for any help,


Brian Davis

Java Blog

Oct 18, 2011 at 2:38 PM

Hey Brian,

I recommend setting a breakpoint with the debugger on this line:

newUrlstart = row["NewUrl"].ToString() + context.Request.Url.AbsoluteUri.Substring(oldPrefix.Length) + (newUrlstart.TrimEnd('/'));

and then hold your cursor over each of the pieces of the expression to see the valuse of the various variables. 

Also, while doing this checkout the other properties of context.Request.Url, there may be other properties there that could be useful for your purposes.


Oct 19, 2011 at 7:45 PM

Its the trim function not working :)


Still figuring it out through.