MVC Razor 路由 .mp3 文件
我有以下 url
Call/GetAudio/f9715595-a540-4add-8419-f9cdf906c7ec.mp3
现在问题是上面的 .mp3 文件实际上并不存在,而是我希望它转到“CallController”、“GetAudio”函数,然后该函数将字节数组作为 FileResult 返回。
我想我需要在 global.asax 中为此配置一些路由,这可以实现吗?
基本上我希望所有 .mp3 文件都经过路由。
I have following url
Call/GetAudio/f9715595-a540-4add-8419-f9cdf906c7ec.mp3
Now the problem is the above .mp3 file does not actually exist, rather I want it to go to "CallController", "GetAudio" function which will then return the bytes array as FileResult.
I imagine I need to configure some routing for this in global.asax, is this achievable?
Basically I want all .mp3 files to go through routing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有路径都将经过路由,无论扩展名如何。
(假设 IIS 已正确配置为使用 ASP.Net 作为通配符处理程序)
只需创建一个正常的路由即可。
请注意,没有理由在 URL 中包含
.mp3
;只需确保在响应中包含适当的Content-Type
即可,无论 URL 是什么,您都应该这样做。All paths will go through routing, regardless of extension.
(assuming IIS is correctly configured to use ASP.Net as a wildcard handler)
Just make a normal route.
Note that there is no reason to include
.mp3
in the URL; just make sure to include an appropriateContent-Type
in the response, which you should do regardless of URL.这是一个类似的答案,只是它提供图像而不是音频文件,但原理是相同的。
ASP.NET MVC 控制器可以返回图像吗?
只需创建一个为 MP3 提供服务的控制器操作。然后您可以删除 .mp3 文件扩展名,因为控制器将仅提供 mp3 的服务。您的路由将是普通路由
{Controller}/{Action}/{id}
Here's a similar answer, only it's serving images instead of audio files, however the principles are the same.
Can an ASP.NET MVC controller return an Image?
Simply create a Controller Action that serves MP3's. Then you can drop the .mp3 file extension since the controller will be serving only mp3's. Your routing will be a normal route
{Controller}/{Action}/{id}