Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual directory inside Orchard web application

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.

like image 998
ajbeaven Avatar asked Feb 20 '12 22:02

ajbeaven


People also ask

What is the virtual directory in IIS?

A virtual directory is a directory name (also referred to as path) that you specify in Internet Information Services (IIS) 7 and map to a physical directory on a local or remote server.

Why do we need virtual directory in IIS?

For example, you might use a virtual directory when you want your application to include images from another location in the file system, but you do not want to move the image files into the physical directory that is mapped to the application's root virtual directory. By default, IIS uses configuration from Web.

How do I create a virtual directory?

Right-click the Web site that you want (for example, Default Web Site), point to New, and then click Virtual Directory. On the Welcome to the Virtual Directory Creation Wizard page, click Next. On the Virtual Directory Alias page, type the alias that you want (for example, Sales), and then click Next.


2 Answers

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.

like image 94
ajbeaven Avatar answered Sep 23 '22 01:09

ajbeaven


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>.

like image 35
Adam Avatar answered Sep 24 '22 01:09

Adam