.NET MVC-控制器/视图和物理路径? [英] .NET MVC - Controller/View and physical path?

查看:213
本文介绍了.NET MVC-控制器/视图和物理路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用URL的控制器/视图:

Is it possible to have controller/view for URL:

http://mydomain/SomeFolder/

和一个类似的物理文件夹将文件放入其中

And a similar physical folder to put files in it

http://mydomain/SomeFolder/*.*

当前的URL http://mydomain/SomeFolder/,仅在web.config允许的情况下返回浏览的物理文件夹,但我希望它返回视图,而http://mydomain/SomeFolder/*.*则返回包含在该文件夹中的文件.

Currently URL http://mydomain/SomeFolder/, only returns the physical folder is browsed if web.config allows it, but I would like it to return the view and http://mydomain/SomeFolder/*.* to return the files contained in the folder.

推荐答案

这是我找到的解决方案,但我希望找到一些更简单的方法.

Here's the solution I found, I whish I had found some simpler way though.

使用此解决方案,我仍然无法将文件放在http://mydomain/SomeFolder/的物理路径中,该文件夹在物理上不能存在,否则控制器/视图无法正常工作. 但是它将实现的是http://mydomain/SomeFolder/SomeFile.zip返回与http://mydomain/**Content**/SomeFolder/SomeFile.zip相同的文件,这是我的主要目标.

With this solution I still cannot put files in the physical path of http://mydomain/SomeFolder/, this folder cannot exist physically otherwise the controller/view doesn't work. But what it will achieve is that http://mydomain/SomeFolder/SomeFile.zip returns the same file as http://mydomain/**Content**/SomeFolder/SomeFile.zip, which was my main goal.

我需要为http://mydomain/SomeFolder/http://mydomain/SomeFolder/anything/file/etc

        routes.MapRoute(
            "SomeFolder",
            "SomeFolder",
            new { controller = "SomeFolder", action = "Index" }
        );

        routes.MapRoute(
            "SomeFolderSub",
            "SomeFolder/{*any}",
            new { controller = "TryDownloadFile", action = "Index" }
        );

routes.RouteExistingFiles仍然是false.

然后我有SomeFolderController可以返回SomeFolder的视图. 然后TryDownloadFileController检查文件是否在http://mydomain/Content/SomeFolder/而不是http://mydomain/SomeFolder/中并返回文件.

Then I have SomeFolderController that return SomeFolder's view. And TryDownloadFileController that checks if the file exists in http://mydomain/Content/SomeFolder/ instead of http://mydomain/SomeFolder/ and returns it.

(我想如果文件不存在,它应该返回一些404响应.应该是return this.HttpNotFound();)

(I guess if the file doesn't exist it should return some 404 response. Which would be return this.HttpNotFound();)

这篇关于.NET MVC-控制器/视图和物理路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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