简体   繁体   English

ASP.NET 4.0 URL路由

[英]Asp.net 4.0 url routing

I'm using the .Net 4.0 framework and doing some url routing. 我正在使用.Net 4.0框架并进行一些url路由。 This is not an MVC project, but a webforms project. 这不是MVC项目,而是Webforms项目。 I've created two routes in the Global.asax like so: 我在Global.asax中创建了两条路由,如下所示:

        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
        );

When I click on a link in the sites navigation like 'documents/pending' it will go to the proper place and display the expected url. 当我单击站点导航中的链接(如“文档/待处理”)时,它将转到正确的位置并显示预期的URL。 If I click again on 'document/accepted' the url will look like: 如果我再次单击“文档/已接受”,则网址将如下所示:

http://localhost/documents/documents/accepted

Also the page is not found and rendered. 此外,找不到页面并呈现。 Same thing will happen if I click the help link then documents. 如果单击帮助链接然后单击文档,也会发生相同的情况。 The url will look like: 该网址将如下所示:

http://localhost/resource/documents/pending

Why is routing concatenating the url? 为什么路由将URL连接起来? How can I fix this? 我怎样才能解决这个问题?

Thanks in advance 提前致谢

The problem's to do with how your URLs are being resolved. 问题与URL的解析方式有关。 For ways to guarantee your URLs are always resolved correctly see http://msdn.microsoft.com/en-us/library/dd329551.aspx . 有关确保始终正确解析URL的方法,请参见http://msdn.microsoft.com/zh-cn/library/dd329551.aspx

Alternatively, I've written a Navigation project that will make your life much easier because it handles all URL building for you, http://navigation.codeplex.com/ . 另外,我编写了一个Navigation项目,它将简化您的生活,因为它可以为您处理所有URL的构建,即http://navigation.codeplex.com/ If you're interested and want any help, just let me know. 如果您有兴趣并需要任何帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM