我希望NancyFX中的路由匹配jpg路径,而不管路径段的数量。 例如,它应该匹配所有:
/image.jpg /foo/image.jpg /foo/bar/baz/foo/baz.jpg这可能吗? 似乎我为NancyFX找到的所有通配符选项都是针对特定路径段而不允许多个段(其中段是由'/'分隔的部分)。
看起来它应该是可能的,因为静态内容服务器需要能够做到这一点。
I want to have a route in NancyFX match an jpg path, regardless of the number of path segments. For example, it should match all of:
/image.jpg /foo/image.jpg /foo/bar/baz/foo/baz.jpgIs this possible? It seems all the wildcard options I find for NancyFX are for a particular path segment and do not allow multiple segments (where a segment is a portion separated by '/').
It seems like it should be possible, as the static content server would need to be able to do this.
最满意答案
Nancy支持路由中的正则表达式。 您可以使用正则表达式将所有路径与.jpg图像匹配,并捕获图像的路径和名称:
public MyModule : NancyModule { public MyModule() { Get[@"(?<imagepath>.*)/(?<imagename>.*.jpg)"] = params => { string path = params.imagepath; string name = params.imagename; return DoStuff(path, name); } } }Nancy supports regular expressions in routes. You can use a regular expression to match all the routes to .jpg images, and capture the path and name of the images:
public MyModule : NancyModule { public MyModule() { Get[@"(?<imagepath>.*)/(?<imagename>.*.jpg)"] = params => { string path = params.imagepath; string name = params.imagename; return DoStuff(path, name); } } }更多推荐
发布评论