简体   繁体   English

如何在web.config文件中设置实时服务器的图像文件夹路径

[英]how to set image folder path for live server in web.config file

I am having following key for image path in web.config file 我在web.config文件中有以下图像路径的密钥

<add key="ImagePath" value="\Images\"/>  

I want to store images in this folder on live site how the value for this will be set here whether the domain name will come because the images are not storing in this path its working fine on local site but not on live site 我想将图像存储在实时站点上的此文件夹中,如何在此处设置域名的值(是否会出现域名),因为图像未存储在此路径中,因此在本地站点上工作正常,但不在实时站点上

If this key is in your web.config file 如果此密钥在您的web.config文件中

<appSettings>
  <add key="ImagePath" value="\Images\"/>
</appSettings>

Then in your server-side code, you can get the image path from configuration to get the Physical Path for storage like so: 然后,在服务器端代码中,您可以从配置中获取映像路径,以获取用于存储的物理路径,如下所示:

var imagePath = ConfigurationManager.AppSettings["ImagePath"];
var physicalPath = Server.MapPath(imagePath);

if (File.Exists(physicalPath))
{
    //... store your images ...
}

This sounds like a permissions issue. 这听起来像是权限问题。

When the IIS worker process tries to write to the /Images/ folder, it is unable as it does not have write permissions. 当IIS工作进程尝试写入/ Images /文件夹时,由于没有写权限,因此它无法执行。 When you run your website locally via Visual Studio it gives the worker process full rights to any folder in your solution - this may be why you can run it locally but not on the server. 当您通过Visual Studio在本地运行网站时,它为工作进程提供了解决方案中任何文件夹的完整权限-这也许就是为什么您可以在本地运行而不在服务器上运行它的原因。

You would need to give the IIS worker process user both Read and Write access to the /Images/ folder. 您需要为IIS工作进程用户提供对/ Images /文件夹的读取和写入访问权限。

However you must ensure you do not give your IIS Worker process user the Read & Execute permission. 但是,您必须确保不授予IIS Worker进程用户“读取和执行”权限。

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

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