2012-07-04 60 views
0

嗨,我很担心如何从我们的.cs页面定制路由 我知道我们可以在global.asax中使用 routeCollection.MapPageRoute(“Default页面“,”默认/ {ProductName}/{CategoryName}“,”〜/ Default.aspx“);关于在asp.net 4.0 Global.asax中的路由

但我想从我们的代码后面的文件自定义URL路由,因为页面的名称来自数据库...我该怎么做,请帮助我出去的家伙......!

+0

和什么是网页的URL喜欢? – codingbiz

+0

http:// localhost:5931 /默认/收音机/ 2 –

回答

0

你可以尝试以下

定义在Global.asax的另一路线如下

route.MapPageRoute("page/{pageid}", "~/thefilethatdisplaypage.aspx"); 
在thefilethatdisplaypage.aspx.cs

protected void Page_Load(object sender, EventArgs e) 
{ 
    string pageId = RouteData.Values["pageid"].ToString(); 
    string content = getPageFromDatabase(pageId); 

    pageDisplayControl.Text = content; 
} 

虽然我不知道你的实施,这应该给你和想法

+0

嘿,我想添加路由在global.asax动态..从.aspx.cs页面我怎么能这样做..我问你 –

+0

这不是一个良好的做法。你为什么想要这样做,可以在global.asax中处理?请解释。 – codingbiz

+0

嘿,我正在准备CMS系统,其中页面将被动态地添加为此目的我需要这种事情......希望你明白... –