文件路径作为 MVC 路由参数 [英] File path as MVC route argument

查看:20
本文介绍了文件路径作为 MVC 路由参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的一部分将存储在多个位置的资源映射到 Web URL 上,如下所示:

Part of my application maps resources stored in a number of locations onto web URLs like this:

http://servername/files/path/to/my/resource/

资源位置是根据文件路径建模的,因此可以有无限级别的嵌套.是否可以构建一个与此匹配的 MVC 路由,以便我将整个路径传递到我的控制器中?可以是单个字符串,也可以是 params 样式的字符串数组.

The resources location is modelled after file paths and as a result there can be an unlimited level of nesting. Is it possible to construct an MVC route that matches this so that I get the path in its entirety passed into my controller? Either as a single string or possibly as an params style array of strings.

我猜这需要匹配 files 关键字,然后是某种通配符.虽然我不知道 MVC 是否支持这一点.

I guess this requires a match on the files keyword, followed by some sort of wildcard. Though I have no idea if MVC supports this.

推荐答案

A route like

A route like

"Files/{*path}"

将获取路径作为单个字符串.* 将其指定为通配符映射,它将使用 "Files/" 之后的整个 URL.

will get the path as a single string. The * designates it as a wildcard mapping and it will consume the whole URL after "Files/".

这篇关于文件路径作为 MVC 路由参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆