Run an ASP.NET website in a subfolder

27,751

Solution 1

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.

Solution 2

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.

Solution 3

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>
Share:
27,751
Bernhard Hofmann
Author by

Bernhard Hofmann

Software Developer #SOreadytohelp

Updated on July 23, 2022

Comments

  • Bernhard Hofmann
    Bernhard Hofmann almost 2 years

    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.

  • o.k.w
    o.k.w over 14 years
    I am assumming you have a web.config in the wiki folder. "/wiki/bin" is automatically located by the runtime.
  • Bernhard Hofmann
    Bernhard Hofmann over 14 years
    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".
  • o.k.w
    o.k.w over 14 years
    Is the "wiki" folder configured as an Application in IIS?
  • Bernhard Hofmann
    Bernhard Hofmann over 14 years
    No, it's just a folder under the main application folder which is running it's own website.
  • o.k.w
    o.k.w over 14 years
    Will "wiki" be an independent app? If so, set the folder as an application. This will isolate the folder from the parent folder.
  • Bernhard Hofmann
    Bernhard Hofmann over 14 years
    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.
  • James
    James almost 13 years
    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.
  • Troy Hunt
    Troy Hunt almost 13 years
    You need an entire, self-contained app in the folder otherwise it will be looking for a bin directory which doesn't exist.
  • Fuchida
    Fuchida almost 10 years
    The live site for the link above is dead. The cached copy can be found here
  • Jonas Äppelgran
    Jonas Äppelgran over 8 years
    If you have <configSection>'s in your web.config, those should be outside the <location> tag.
  • Muhammad Adeel Zahid
    Muhammad Adeel Zahid over 8 years
    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
  • Adam Baxter
    Adam Baxter about 8 years
    Cached copy has been pulled due to archive.org's robots.txt policy.
  • VDWWD
    VDWWD almost 7 years