I have a web site with some articles inside. Articles are accessed using a database writing results on a single page. When a certain article is to be accessed, I need the article-id and I only need to get to the page: http://www.mysite/Articles.aspx?a={article-id}
.
This is nice but not really friendly and not scalable. What I want to do is to redirect every url in the form: http://www.mysite/articles/{article-id}
to the page http://www.mysite/Articles.aspx?a={article-id}
.
I know that using Web.Config
I can use the urlMappings
settings, but do not know how to insert a regex there.
Please consider that I would like to have a simple translation tool. I do not want to edit my existing pages. This solution should be as transparent as possible to my application components.
What is the best practice to get to the solution?
I think you should use:
Eg.:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Articles",
"articles/{article-id}/",
"~/Articles.aspx");
}
& on "Articles.aspx.cs" you can get the "article-id" using:
string article-id = Page.RouteData.Values["article-id"] as string;