简体   繁体   中英

Debug with IIS Express and access files above root

I am developing an ASP.Net project with Visual Studio that is hosted on a local IIS server. The entire site is fairly complicated, and made up of multiple applications, so I am using a Solution/Project that just consists of the current project in its subdirectory.

My application needs to access files that are outside its subdirectory, and I want to use Server.MapPath to access from the root of the actual web site and still be able to debug in IIS Express.

I can't seem to setup or create proper application settings in my subdirectory in IIS Express that allows root access (three folders above the project folder).

Example: I have my app in /Apps/App1 and I have data it accesses in /Data/Data1 but I have the VS Solution setup in /Apps/App1. On the real web server, Server.MapPath("/Data/Data1/file") works fine, but not in IIS Express since / is relative to /Apps/App1.

The account that ASP.NET runs by default will not have rights to access files outside its Virtual Directory. You need to impersnate your part of code with a account which has higher previlage. Or set impersnation in web.config (which is a bit risky) Here are some articles explaing these

ASP.NET - Reading and writing to the file-system, outside the application

http://www.west-wind.com/weblog/posts/2005/Feb/24/Using-programmatic-Impersonation-from-an-ASPNET-Page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM