2

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.

Abbas
  • 4,948
  • 31
  • 95
  • 161
  • Read about [Medium Trust](http://stackoverflow.com/questions/2617454/what-is-medium-trust-in-asp-net) against Full Trust. Also here http://www.smarterasp.net/support/KB/a252/whats-difference-between-aspnet-full-trust-medium-trust.aspx – Steve Oct 30 '13 at 16:44
  • Hi @Steve can you tell me how can i define trust levels, because i have dedicated server for my websites. So i think i can go with this. So if i have full trust then can i do the above task? – Abbas Oct 30 '13 at 16:51

2 Answers2

2

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
  • Hi @Anderson, how can i create the directory outside my website as a virtual directory, because that directory won't be available in IIS for making it virtual, however i tried keeping that folder under one of the website and made it virtual, but that too didn't helped. – Abbas Oct 30 '13 at 16:53
  • This was the easiest, fastest and safest solution thanks a lot @Anderson – Abbas Oct 30 '13 at 18:04
1

You need to set the Trust Level of your whole site to Full Trust

Just open the IIS Manager, click on the root node and double click on NET Trust Levels. Here you can experiment with various Trust levels to see if your Server.MapPath allows cross site paths

Here an article with details on how to do it also with a command line

Steve
  • 213,761
  • 22
  • 232
  • 286