SEO URL重写ASP.NET [英] SEO URL rewriting ASP.NET
问题描述
我已经有一个ASP.NET网站
I already have an ASP.NET Web Site
我想改变我的网站更加SEO友好的URL
I want to change my site to be more SEO url friendly.
我要改变前。这个网站:
www.mydomain.aspx?=条款ArticleID 5
I want to change ex. this site: www.mydomain.aspx?articleID=5
到:
www.mydomain /条/ learningURLrewrite
- articlename需要从DB中读
to: www.mydomain/article/learningURLrewrite - articlename needs to be read from DB
我如何做到这一点?
我已经尝试与谷歌的一些文章,其中提到的IHttpModule没有任何运气。
I have already tried with some articles from Google which mentions IhttpModule without any luck.
我的目标是有责任的一类重定向基于FOLDERPATH(像这样):
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
}
此外,我想删除ASPX扩展
Also I want to remove the aspx extension
推荐答案
您可以使用太与ASP.NET的WebForms路由。
You can use routing with ASP.NET WebForms too.
的步骤是:
-
在应用程序启动添加路由(或路由)。
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");
}
创建Article.aspx作为一个正常的表单
Create the Article.aspx as a normal webform
在code为Article.aspx,您可以访问这样的URL路径:
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...
}
这篇关于SEO URL重写ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!