简体   繁体   中英

Asp.net 4.0 url routing

I'm using the .Net 4.0 framework and doing some url routing. This is not an MVC project, but a webforms project. I've created two routes in the Global.asax like so:

        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. 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? How can I fix this?

Thanks in advance

The problem's to do with how your URLs are being resolved. For ways to guarantee your URLs are always resolved correctly see http://msdn.microsoft.com/en-us/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/ . If you're interested and want any help, just let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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