Search code examples
asp.netrootloadcontrolvirtual-path

Accessing folder outside website's root folder in asp.net


I have a around 15 websites on a server, i have built a tool which is common across all the sites.

Now instead of keeping the same files inside individual site's folder, i decided to keep the folder common, and keep it outside the website's folder, so that i don't have to keep the files under all the sites.

But my problem is if the folder is outside the website's root folder, i am unable to access it, as Server.MapPath does not works.

I even tried to keep those files under a folder in one of the site's root, and access them like http://domain.com/folder/control.ascx but that too does not works. it throws error saying :http:/domain.com/folder/control.ascx' is not a valid virtual path

Can anyone help me about how could i access the files outside the root folder, or keeping it inside one the site's root folder.


Solution

  • Have you tried adding a virtual directory under your site that points to the common directory?

    Server
      Sites
        Common - base directory is C:\sites\common\
        SiteA - base directory is C:\sites\siteA\
          common - virtual directory pointing to C:\sites\common
        SiteB - base directory is C:\sites\siteB\
          common - virtual directory pointing to C:\sites\common