对于采用 CIDR 表示法的 IP 地址,Slug 应该是什么样子? (例如10.10.10.77/28)
ASP.NET MVC 应用程序需要显示此 URL http://host.com/IPAddress/10.10.10.77/28
;但是句点 .
和正斜杠 /
与 ASP.NET MVC 冲突。
我应该如何处理这个请求?我想到的一些方法包括:
将问题字符串替换为“magic”字符串,例如 10-10-10--28,然后将其转换回逻辑值
在值前面加上 Key,因此该值只是一个 slug:
http://host.com/IPAddress/27/10-10-10--28
查看上面的条目,我失去了直接关闭 IP 地址的能力,但它看起来仍然不正确
配置 ASP.NET 以忽略句点(以某种方式)并忽略最后一个斜杠(可能通过路由)
http://host.com/IPAddress/10.10.10.77/28
我没有对 IPv6 考虑太多,但我想我也需要包括这方面的计划。您认为我应该如何解决这个问题?
An ASP.NET MVC app needs to display this URL http://host.com/IPAddress/10.10.10.77/28
; however the periods .
and forward slashes /
conflict with ASP.NET MVC.
How should I handle this request? Some approaches I thought of include:
Replace the problem strings with "magic" strings such as 10-10-10--28, then convert that back to the logical value
Preface the value with the Key, so the value is just a slug:
http://host.com/IPAddress/27/10-10-10--28
Looking at the entry above I lose ability to key directly off an IP address and it still doesn't look right
Configure ASP.NET to ignore periods (somehow) and ignore the last slash (perhaps by routing)
http://host.com/IPAddress/10.10.10.77/28
I haven't thought much about IPv6, but I suppose I need to include plans for that as well. How do you think I should approach this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于它与 MVC 冲突,而在于它与默认路由语法不匹配。要创建匹配此语法的路由,我相信最好的路由是使用基于正则表达式的路由。这是我以前使用过的: http://www.iridescent.no/Posts/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx。您将需要 v4 和 v6 地址的表达式。
希望这有帮助。
The issue isn't that it conflicts with MVC, it's that it doesn't match the default route syntax. To create a route to match this syntax I believe the best route is to use a RegEx-based route. This is one I've used before: http://www.iridescence.no/Posts/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx. You will need an expression for both v4 and v6 addresses.
Hope this helps.