ASP.Net WebForms - 动态SEO友好的URL

3

我已经阅读了很多关于ASP.Net中SEO友好URL功能的内容。大部分都涉及将使用查询字符串参数的URL转换为美观的URL。我对使标准URL变得美观感兴趣。例如:

http://mysite.com/aboutus.aspx

should be...

http://mysite.com/about-us

我发现以下代码满足要求:
void Application_Start(object sender, EventArgs e) 
{
    // Enable routing
    RegisterRoutes(RouteTable.Routes);
}

void RegisterRoutes(RouteCollection routes)
{        
    // About us section routes
    routes.MapPageRoute(
        "AboutUsRoute",
        "{about-us}",
        "~/aboutus.aspx"
     );
}

我的问题是我需要为站点中的每个页面手动指定路由。有更好的方法吗?


1
我会建议只使用MVC...虽然这并没有回答问题,但它确实是一个解决方案 :) - Andrew Grothe
2
@agrothe,这是一个非常糟糕的解决方案。我不想引发争端,但我更喜欢Web表单。为什么?因为这是我目前感到舒适的方式。 - James Hill
2
看起来你需要动态路由,请参考这里:http://stackoverflow.com/questions/890275/webforms-custom-dynamic-routing - Andrew Grothe
@James_Hill 没错,不要引发争论!MVC确实使SEO URL更容易,但使用Webforms仍然是可能的。可以使用先前链接中的pageprocessor思想,或者过去我曾经使用单个查询字符串,例如domain.com/?Content=News/World/some-content-page。 - Andrew Grothe
@JDandChips,它确实适用,但这正是我正在使用的。我试图避免为每个页面创建一个路由。 - James Hill
显示剩余3条评论
2个回答

3
这个简单的路由将把路由网址映射到物理的.aspx页面。
routes.MapPageRoute("Page", "{name}", "~/{name}.aspx");

因此,/about 对应于 /about.aspx/contact-us 对应于 contact-us.aspx,等等。


3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接