21

Is there a way of running an ASP.NET website in a subfolder of the website?

As an example, say I wanted to run the screwturn wiki (http://www.screwturn.eu/) in a folder called "wiki" on my website, can I alter the web.config of the screwturn website to tell it that it is running in the "wiki" folder? (like saying that "~/" = "/wiki/")

The wiki would then find its assemblies that are in "~/bin" in "/wiki/bin" and the same for all other folders below the new root.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Bernhard Hofmann
  • 10,321
  • 12
  • 59
  • 78

5 Answers5

14

Piece of cake, you can either add a virtual directory to the root of the IIS website and point it at the path of your site or place it an a physical directory in the website root then turn it into an application by right-clicking on it in the IIS management console, going to properties and clicking "Create" next to application name.

Troy Hunt
  • 20,345
  • 13
  • 96
  • 151
  • Although I didn't mention it, I do not have control of the web server. But this is the nearest to the solution I took, which was to create a subdomain (wiki.mydomainname.org). I'll mark this as the answer because your suggestions are on the mark had I had access to IIS on the ISPs box. – Bernhard Hofmann Oct 22 '09 at 07:29
  • I tired this but now IIS is complaining that in cant find the code behind class for the login page. Do sub sites inherit the same dlls as the parent? Because the login in page class for the sub site is compiled into the main sites dll as its all the same project in VS. – James Aug 02 '11 at 15:05
  • 1
    You need an entire, self-contained app in the folder otherwise it will be looking for a bin directory which doesn't exist. – Troy Hunt Aug 02 '11 at 20:11
  • 1
    What if someone does not have access to IIS settings? I don't have access to the web.config of root application. Is there a way to make a web application in sub directory – Muhammad Adeel Zahid Feb 04 '16 at 10:02
11

You need to stop the configuration inheritance in the root web.config file so that the wiki web.config doesn't read anything from the root web.config.

Undo
  • 25,519
  • 37
  • 106
  • 129
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • 1
    The live site for the link above is dead. The cached copy can be found [here](http://web.archive.org/web/20131024031827/http://www.aspdotnetfaq.com/Faq/how-to-disable-web-config-inheritance-for-child-applications-in-subfolders-in-asp-net.aspx) – Fuchida Aug 02 '14 at 21:24
  • Cached copy has been pulled due to archive.org's robots.txt policy. – Adam Baxter May 09 '16 at 00:16
  • See https://stackoverflow.com/questions/782252/avoid-web-config-inheritance-in-child-web-application-using-inheritinchildapplic – VDWWD Jun 27 '17 at 07:20
5

As others pointed out. basically you need to put this in your child application Web.config, of course you also need to configure the domain (sub domain etc.), IIS setting as well.

<configuration>    
  <location path="." inheritInChildApplications="false">

    //your code here

    <system.web>
      //your code here
    </system.web>

    //your code here

  </location>     
</configuration>
Ronaldinho Learn Coding
  • 13,254
  • 24
  • 83
  • 110
0

I had to do this recently, and having made the wiki folder an application (as suggested in the previous answers) I also had to place a dummy 'App_Themes -> Default' folder at the top-level within the Wiki app because of the presence of the <pages styleSheetTheme="default" theme="default"> tag in the parent app's Web.config. Small hack, but that's the way I like to configure my styles in Asp.Net, and I didn't want to change that.

Ralph Lavelle
  • 5,718
  • 4
  • 36
  • 46
-1

Short answer is YES you can. No need to specify the location of the folder in the Web.Config.

o.k.w
  • 25,490
  • 6
  • 66
  • 63
  • I am assumming you have a web.config in the wiki folder. "/wiki/bin" is automatically located by the runtime. – o.k.w Oct 04 '09 at 09:58
  • But the pages fail to load, claiming that "The file '/MasterPage.master' does not exist.". The aspx page directive has MasterPageFile="~/MasterPage.master". The question is how I make that resove to "/wiki/MasterPage.master" rather than "/MasterPage.master". – Bernhard Hofmann Oct 04 '09 at 10:01
  • Is the "wiki" folder configured as an Application in IIS? – o.k.w Oct 04 '09 at 10:02
  • No, it's just a folder under the main application folder which is running it's own website. – Bernhard Hofmann Oct 04 '09 at 10:06
  • Will "wiki" be an independent app? If so, set the folder as an application. This will isolate the folder from the parent folder. – o.k.w Oct 04 '09 at 10:07