Asp.net 4.0 url路由连接url

发布于 2024-12-21 12:51:52 字数 821 浏览 3 评论 0原文

我正在使用 .Net 4.0 框架并执行一些 url 路由。这不是一个MVC项目,而是一个winform项目。我在 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
        );

当我单击站点导航中的链接(例如“documents/pending”)时,它将转到正确的位置并显示预期的 url。如果我再次单击“文档/已接受”,URL 将如下所示:

http://localhost/documents/documents/accepted

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

http://localhost/resource/documents/pending

为什么路由要串联该 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-12-28 12:51:52

我认为如果它们总是要到达根目录,您需要以不同的方式设置路线。像这样的事情:

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

原因是您将 document/page.aspx 附加到您所在级别的末尾。因此,如果您位于 http://localhost/this/next/folder/document/accept
并且您路由下一个会将路由附加到您当前的目录,因此 http://localhost/this/next/folder/document/document/accept 但如果您像我上面显示的那样进行路由,它将执行这将带您到http://localhost/document/accept

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文