如何让文件夹和控制器具有相同名称的ASP.NET MVC? [英] How to have folder and controller with same name in ASP.NET MVC?

查看:268
本文介绍了如何让文件夹和控制器具有相同名称的ASP.NET MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC控制器称为下载。 HTTP:// mysite的/下载

I have a MVC controller called Downloads. http://mysite/Downloads

我也想提出一个物理文件名为 HTTP一个物理文件夹://mysite/Downloads/MyFile.zip

I also want to put a physical file in a physical folder called http://mysite/Downloads/MyFile.zip.

如果我简单地创建一个文件夹,我浏览到 HTTP时得到一个403。 (最有可能是因为目录浏览被禁用) 但我想MVC的控制器中,而不是踢。

If I simply create a folder, I get a 403 when browsing to http://mysite/Downloads. (Most likely because of directory browsing is disabled) But I want the MVC controller to kick in instead.

我该怎么办呢?

推荐答案

如果您浏览到的http:// mysite的/下载/ {行动} 它会触发您的控制器采取行动。

If you browse to http://mysite/Downloads/{ACTION} it will fire your controllers action.

这会不会在你的榜样工作的唯一的事情就是 /下载没有采取行动。你可以重写这个URL重定向你到你的默认操作。

The only thing that won't work in your example is the /Downloads with no action. You could re-write this URL to redirect you to your default action.

此外,你需要有routehandler忽略你的下载文件。您可以在Global.asax文件中添加一行忽略所有zip文件或适合其他一些忽略模式。

In addition, you will need to have the routehandler ignore your download files. You can add a line in your global.asax file to ignore all zip files or some other ignore pattern that suits.

routes.Ignore("{resource}.zip");

这篇关于如何让文件夹和控制器具有相同名称的ASP.NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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