rross
rross

Reputation: 2276

Asp.net 4.0 url routing concatinating url

I'm using the .Net 4.0 framework and doing some url routing. This is not an MVC project, but a winform 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

Upvotes: 1

Views: 285

Answers (1)

CBRRacer
CBRRacer

Reputation: 4659

I think you need to set your route differently if they are always going to be going to the root. Something like this:

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

the reason is that you are appending the document/page.aspx to the end of whatever level you are at. So if you are at http://localhost/this/next/folder/document/accept and you route the next one will append the route to your current directory so http://localhost/this/next/folder/document/document/accept but if you route like I showed above it will do this take you to http://localhost/document/accept

Upvotes: 1

Related Questions