问题
I would like to have a /downloads folder inside an Orchard web app where I can direct clients to so they can download files ie. www.mydomain.com/downloads/test.txt
In IIS I have created a virtual directory (not an Application) underneath the Orchard website that points to the downloads folder on the server.
In the Orchard Global.ascx file, I've added the following, thinking that it was a routing problem:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("downloads/{*pathInfo}"); // added this IgnoreRoute
}
Not 100% sure if this is required.
However, when I go to download the file, www.mydomain.com/downloads/test.txt, I continue to receive a 404 error.
回答1:
Found the fix thanks to this post: http://orchard.codeplex.com/discussions/280041
Firstly, it needed to be an application under the Orchard website, rather than just a virtual directory. In IIS you can right click on the virtual directory > convert to Application.
After that, the issue is that the web.config in Orchard propagates to the child applications. To stop this, you need to add <location path="." inheritInChildApplications="false">
around both the <system.web>
and <system.webserver>
nodes in Orchard's web.config file. You can read more on the location tag here.
After making those changes, I can then successfully download my test.txt file with no problems.
回答2:
Brilliant, thank you so much for this answer. After implementing it straight off here my Orchard styles broke, but after having a look at that link, I noticed this bit of code:
<location path="Themes">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers accessPolicy="Script">
<remove name="StaticFile" />
</handlers>
</system.webServer>
</location>
<location path="Core">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers accessPolicy="Script">
<remove name="StaticFile" />
</handlers>
</system.webServer>
</location>
<location path="Media">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers accessPolicy="Script">
<remove name="StaticFile" />
</handlers>
</system.webServer>
</location>
<location path="Modules">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers accessPolicy="Script">
<remove name="StaticFile" />
</handlers>
</system.webServer>
</location>
Which will fix your Orchard style, for anyone having that issue.
It should be placed in the web.config file in the root of your site, just before the <runtime>
and after the last </location>
that you will have just added to finish wrapping <system.webServer>
.
回答3:
You don't necessarily need to hack the config under orchard. In a similar situation for me there was enough to create a web.config under the virtual directory with the following content:
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Script">
<clear />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Script" />
</handlers>
</system.webServer>
来源:https://stackoverflow.com/questions/9369625/virtual-directory-inside-orchard-web-application