1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Your correct. The the change I had to do to make it work was with the linking url. Previously I was linking to 'documents/pending' I change that do '/documents/pending', and all is working. When I tried to add '~/' to my Route URL it threw this error: The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character. Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.