I already have an ASP.NET Web Site
I want to change my site to be more SEO url friendly.
I want to change ex. this site: www.mydomain.aspx?articleID=5
to: www.mydomain/article/learningURLrewrite - articlename needs to be read from DB
How do I accomplish this?
I have already tried with some articles from Google which mentions IhttpModule without any luck.
My goal is to have a class responsible for redirecting based on folderpath(like this):
string folderpath = "my folderpath" (could be articles, products etc.)
string id = Request.QueryString["id"].ToString();
if(folderpath.equals("articles"))
{
string name = //find name from id in DB
//redirect user to www.mydomain/article/name
}
if(folderpath.equals("products"))
{
string name = //find name from id in DB
//redirect user to www.mydomain/products/name
}
Also I want to remove the aspx extension
You can use routing with ASP.NET WebForms too.
The steps are:
Add the route (or routes) at application start.
//In Global.asax
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("My Routename", "{*name}", "~/Article.aspx");
}
Create the Article.aspx as a normal webform
In the code for Article.aspx, you can access the url path like this:
public void Page_Load(object sender, EventArgs e)
{
var thePath = RouteData.Values["name"];
// Lookup the path in the database...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With