Asp.net 4.0 url路由连接url
我正在使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果它们总是要到达根目录,您需要以不同的方式设置路线。像这样的事情:
原因是您将 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:
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 tohttp://localhost/document/accept