2011-12-15 102 views
1

我使用.Net 4.0框架,并做一些网址路由。这不是一个MVC项目,而是一个winform项目。我创建了两条路线在Global.asax像这样:Asp.net 4.0网址路由协同网址

 routes.MapPageRoute(
      "review",  // Route name 
      "documents/{type}",  // Route URL 
      "~/default.aspx" // Web page to handle route 
     ); 

     routes.MapPageRoute(
      "help",  // Route name 
      "resource/help",  // Route URL 
      "~/help.aspx" // Web page to handle route 
     ); 

当我点击网站导航像一个链接上的“文件/挂起”,它会转到合适的位置,并显示预期的URL。如果我再次点击'document/accepted',网址将如下所示:

http://localhost/documents/documents/accepted 

此外,未找到并呈现页面。如果我点击帮助链接然后点击文档,也会发生同样的事情。该网址将如下所示:

http://localhost/resource/documents/pending 

为什么路由连接url?我怎样才能解决这个问题?

在此先感谢

回答

1

我认为你需要设置你的路线不同,如果他们总是会被分配给根。事情是这样的:

 routes.MapPageRoute(
     "review",  // Route name 
     "~/documents/{type}",  // Route URL 
     "~/default.aspx" // Web page to handle route 
    ); 

    routes.MapPageRoute(
     "help",  // Route name 
     "~/resource/help",  // Route URL 
     "~/help.aspx" // Web page to handle route 
    ); 

的原因是要附加的文件/ page.aspx到你在任何级别的结束。所以,如果你是在http://localhost/this/next/folder/document/accept 和你路由的下一个将路由添加到您的当前目录中,以便http://localhost/this/next/folder/document/document/accept,但如果你像我的路线表明,它上面会做到这一点带你到http://localhost/document/accept

+0

你是正确的。我必须做的改变才能使它工作的是链接网址。以前我链接到'documents/pending'我改变了'/ documents/pending',并且一切正常。当我试图向我的路由URL添加'〜/'时,它抛出了这个错误:路由URL不能以'/'或'〜'开头,它不能包含'?'字符。谢谢你的帮助 – rross 2011-12-15 15:27:49