简体   繁体   中英

Accessing a file in the iis folder from asp.net

Im using C# to try save a file to an iis "temp" folder path, it works locally but wheh i publish the app and access it from another computer it uses the full path (C:/....) and cant find it as its looking for a local directory, how can i fix this?

(Server.MapPath("~/TEMP/") + filename); // code to savefile

Thanks

well a nice improvement you can do is:

1) add an absolute path as appSetting to your application web config, something like: \\\\MachineName\\ShareName

2) create the ShareName network share on the machine MachineName (this could be your server where you publish the application or another server as well, up to your needs)

3) allow the IIS user or the application pool's identity user to access in read-write to the share: \\\\MachineName\\ShareName

4) edit your code above to do something like:

Path.Combine(sharePath, filename);

where sharePath is a string initialized with the value from your web.config's appSetting using ConfigurationManager.AppSetting["settingName"]

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