简体   繁体   中英

Relative path from Service Website on Azure Cloud Service

I have a Azure Cloud Service with a WCF web role. I am trying to access a file within App_Data and I don't want to hardcode the path. I've tried using:

System.Web.HostingEnviroment.MapPath("~/App_Data/myfile");

as well as turning on aspNetCompatibilityEnabled and using Server.MapPath()

but both ways return:

d:\\windows\\system32\\inetsrv\\App_Data\\myfile

The actual location of the file is:

E:\\sitesroot\\0\\App_Data\\myfile

Is there any way I can access this file short of hard-coding the path?

After deployment azure cloud service will deploy the application to a VM. So accessing the files from any subfolder with relative path does not change.

You can read the file without mapping virtual file. You can load the file passing just below file path. "/App_Data/myfile"

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