ASP.NET MVC路由和文件路径

时间:2022-08-26 20:48:49

I have a controller action that has the same name as a file path. Like:

我有一个与文件路径同名的控制器操作。喜欢:

www.example.com/userfiles/path/to/userfile.jpg

Basically I have a userfiles controller and on the index action everything after userfiles/ is a path. There is also a userfiles virtual directory in the root of my application. What I want to happen is that if the directory that follows userfiles/ (in this case path) does not exist in the userfiles virtual directory, then use the index action on the userfilesController if the directory does exist, then use the path as it is.

基本上我有一个userfiles控制器,在userfiles /之后的所有内容都是一个路径。在我的应用程序的根目录中还有一个userfiles虚拟目录。我想要发生的是,如果userfiles /(在这种情况下是路径)后面的目录在userfiles虚拟目录中不存在,那么如果目录确实存在,则在userfilesController上使用index操作,然后使用路径,因为它是。

This worked flawlessly on my windows xp dev machine running iis 5. But, once I moved it to the live server(Windows server 2003 iis 6), I get a 404 error as if the path does not exist rather than going to the userfiles controller index action.

这在我运行iis 5的windows xp dev机器上完美运行。但是,一旦我将它移动到实时服务器(Windows server 2003 iis 6),我得到一个404错误,好像路径不存在而不是转到userfiles控制器指数行动。

In the routes file I have:

在路线文件中我有:

routes.MapRoute(
    "Userfiles",                                       // Route name
    "userfiles/{*url}",                                // URL with parameters
    new { controller = "Userfiles", action = "Index" } // Parameter defaults
);

What am I missing? It was working so well.

我错过了什么?它工作得很好。

2 个解决方案

#1


1  

So I found out that my issue was that we did have wildcard mapping enable for the site however, we also had turned it off for certain directories because of performance. I have re-enabled the wildcard for the directory in question and it all started working as it had on my dev box. Joy!

所以我发现我的问题是我们确实为网站启用了通配符映射,但是由于性能的原因,我们也为某些目录关闭了它。我已经为相关目录重新启用了通配符,并且它在我的开发框中开始工作。喜悦!

#2


0  

I know this has already been answered by thought this might help someone. In your web.config you may need to add runAllManagedModulesForAllRequests="true"

我知道这已经被认为可以帮助某人。在您的web.config中,您可能需要添加runAllManagedModulesForAllRequests =“true”

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />

Hope this helps someone.

希望这有助于某人。

#1


1  

So I found out that my issue was that we did have wildcard mapping enable for the site however, we also had turned it off for certain directories because of performance. I have re-enabled the wildcard for the directory in question and it all started working as it had on my dev box. Joy!

所以我发现我的问题是我们确实为网站启用了通配符映射,但是由于性能的原因,我们也为某些目录关闭了它。我已经为相关目录重新启用了通配符,并且它在我的开发框中开始工作。喜悦!

#2


0  

I know this has already been answered by thought this might help someone. In your web.config you may need to add runAllManagedModulesForAllRequests="true"

我知道这已经被认为可以帮助某人。在您的web.config中,您可能需要添加runAllManagedModulesForAllRequests =“true”

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />

Hope this helps someone.

希望这有助于某人。