David
David

Reputation: 163

url rewrite path

I am trying to rewrite a url in an httpmodule. If I have the string "/learning/index.aspx". I want to rewrite it to "/learning/pages/index.aspx"

The rewrite will always put the "pages" in the same position in the string, before the last "/", so "/index, would become /page/index.aspx, or /topics/topic1.aspx, would become /topics/pages/topic1.aspx.

What would be the correct c# code to do this?

Upvotes: 2

Views: 336

Answers (1)

Try this as an example:

string myUrl = "/learning/index.aspx";
myUrl = myUrl.Insert(myUrl.LastIndexOf("/"), "/pages");
MessageBox.Show(myUrl.ToString());

You can use LastIndexOf to find out where the last slash is, and insert your "/pages" string from there.

Upvotes: 2

Related Questions