如何让文件夹和控制器具有相同名称的ASP.NET MVC?控制器、文件夹、名称、MVC

由网友(ら人已逝)分享简介:我有一个MVC控制器称为下载。 HTTP:// mysite的/下载 I have a MVC controller called Downloads. http://mysite/Downloads我也想提出一个物理文件名为 HTTP一个物理文件夹://mysite/Downloads/MyFile.zip 。...

我有一个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");
阅读全文

相关推荐

最新文章