Asp.net mvc 路由在通配符末尾删除数字文件夹
因此,我们有一个路由设置,在末尾有一个通配符来捕获文件路径,该路由可能如下所示:
/{browserName}/{browserVersion}/{locale}/{*packageName}
当我们尝试路径如:
/FF/3/en-US/scripts/packages/6/super.js
最终传递给控制器的 packageName 是:
/scripts/packages/super.js
使用路由测试程序也会发生这种情况我们完全不明白这是为什么。如果您用字符串替换 6,它会起作用,如果您在 6 之前添加另一个数字文件夹,它就会被包含在内,因此如果最后一个文件夹是数字,它看起来就会被删除。有谁知道这是为什么吗?
So we have a route setup that has a wildcard at the end to capture a file path, the route might look like:
/{browserName}/{browserVersion}/{locale}/{*packageName}
The problem comes in when we try a path like:
/FF/3/en-US/scripts/packages/6/super.js
What ends up getting passed to the controller as packageName is:
/scripts/packages/super.js
Using the route tester program this also happens so we're at a total loss of why this is. If you replace the 6 with a string, it works, if you add another numeric folder before the 6 it does get included so it appears to just drop if the last folder is numeric. Anyone know why this is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在VS2008中创建了默认的asp.net mvc2项目,并更改了以下代码:
在 global.asax.cs 中,我有以下代码:
接下来我添加了一个 TestController:
和一个空的索引视图:
指数
索引
为了方便起见,我在 site.master 中为您指定的 url 添加了一个链接:
接下来,我在 TestController 的 Index 操作中设置了一个断点。
当我将鼠标悬停在 packageName 参数上时,我看到“scripts/packages/6/super.js”,
所以我无法重现您得到的行为。
您使用的是VS2008和MVC2还是其他版本?
I created the default asp.net mvc2 project in VS2008 and changed the following code:
In the global.asax.cs I have this code:
And next I added a TestController:
And a empty Index View:
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
</asp:Content>
for convenience I added a link in the site.master for the url you specified:
Next I set a breakpoint in the Index action of the TestController.
When I hover over the packageName parameter I see "scripts/packages/6/super.js"
So I can't reproduce the behavior you got.
Are you using VS2008 and MVC2 or other versions?