简体   繁体   English

从asp.net访问iis文件夹中的文件

[英]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? 我使用C#尝试将文件保存到iis“temp”文件夹路径,它在本地工作,但是当我发布应用程序并从另一台计算机访问它时,它使用完整路径(C:/ ....)并且无法找到它作为寻找本地目录,我该如何解决这个问题?

(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 1)在应用程序Web配置中添加一个绝对路径作为appSetting ,类似于: \\\\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) 2)在MachineName机器上创建ShareName网络共享(这可能是您发布应用程序或其他服务器的服务器,根据您的需要)

3) allow the IIS user or the application pool's identity user to access in read-write to the share: \\\\MachineName\\ShareName 3)允许IIS用户或应用程序池的标识用户以读写方式访问共享: \\\\MachineName\\ShareName

4) edit your code above to do something like: 4)编辑上面的代码,执行以下操作:

Path.Combine(sharePath, filename);

where sharePath is a string initialized with the value from your web.config's appSetting using ConfigurationManager.AppSetting["settingName"] 其中sharePath是使用ConfigurationManager.AppSetting["settingName"]使用web.config的appSetting中的值初始化的字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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