简体   繁体   English

将Web服务的输出存储在虚拟目录中

[英]To store the output of web service in virtual directory

I have created a web service which gives the data in JSON format, I am going to read this data to create a high-charts. 我创建了一个以JSON格式提供数据的Web服务,我将读取此数据以创建高级图表。 When I coded this web service , I get values in string which I have serialized into JSON format and store it my folder on system, but problem is when I will deploy my web service in remote machine that time I will face the problem to store the file since I have provided local path as explained in below code, 当我编写这个Web服务时,我得到了字符串中的值,我将其序列化为JSON格式并将其存储在系统上,但问题是当我将在远程机器中部署我的Web服务时,我将面临存储问题的问题。文件,因为我提供了本地路径,如下面的代码所述,

System.IO.File.WriteAllText(@"C:\Json\Json.json", jSearializer.Serialize(modified_listofstrings));

Can anyone please suggest what I am suppose to do so that I can store this file in such a way that it will be easy to access after deployment of my web service in remote machine? 任何人都可以建议我这样做,以便我可以存储这个文件,以便在远程机器上部署我的Web服务后很容易访问?

Is that possible or I will have to create a simple asp.net application and consume that web service and store that file in the folder of that newly created application? 这是可能的还是我将不得不创建一个简单的asp.net应用程序并使用该Web服务并将该文件存储在新创建的应用程序的文件夹中?

I am very new to this concept hence I don't know about storing in virtual folder or something like that, I got suggestion to do so, It will be very grateful if someone explains me the concept as well... 我对这个概念很新,因此我不知道存储在虚拟文件夹或类似的东西,我有建议这样做,如果有人向我解释这个概念,我将非常感激......

You have two ways: 你有两种方式:

  1. Give write permission to your application identity to write in c:\\json folder, which is not a good idea. 为您的应用程序标识提供写入权限以写入c:\\json文件夹,这不是一个好主意。

  2. Change your code to use relative path: 将代码更改为使用相对路径:

     File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("/json"), "json-text"); 

Server.MapPath maps a virtual directory to it's equivalent absolute directory in OS. Server.MapPath将虚拟目录映射到OS中等效的绝对目录。 For example, if your website is hosted in c:\\websites\\json-project\\ , then using Server.MapPath("/foo") would be translated to c:\\websites\\json-project\\foo path. 例如,如果您的网站托管在c:\\websites\\json-project\\ ,则使用Server.MapPath("/foo")将转换为c:\\websites\\json-project\\foo path。

By default any ASP.NET application has full access to all of its folders. 默认情况下,任何ASP.NET应用程序都可以完全访问其所有文件夹。

You can find the physical path to your application by giving relative path something like Server.MapPath("/Json/Json.json") 您可以通过提供类似Server.MapPath("/Json/Json.json")相对路径来查找应用程序的物理路径

for more information check below SO question 有关更多信息,请查看下面的问题

Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\\"), Server.MapPath("/"). Server.MapPath(“。”),Server.MapPath(“〜”),Server.MapPath(@“\\”),Server.MapPath(“/”)。 What is the difference? 有什么区别?

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

相关问题 虚拟目录和Web服务 - Virtual Directory and Web Services 如何在Web服务安装期间更改默认的虚拟目录名称? - How do I change the default Virtual Directory name during a web service install? 即使虚拟目录允许匿名访问,Web 服务也会出现“HTTP 状态 401:访问被拒绝”错误 - "HTTP status 401: Access Denied" error for web service even when the virtual directory allows Anonymous access 获取Window Service中虚拟目录的物理路径 - Get Physical path of Virtual Directory in Window Service 共享主机虚拟目录中的 Wcf 服务 - Wcf service in virtual directory on shared hosting ASP.NET Web服务的本地和远程服务器上的输出目录路径 - Output directory path both locally and on remote server for ASP.NET Web Service 存储Web服务异常的位置? - Where to store web service exceptions? 用于远程Web服务的Windows虚拟磁盘 - Windows virtual disk for remote web service 如何将Web服务器中的目录作为虚拟目录添加到iis - How to add a directory located in a web server to iis as a virtual directory 如何从未与虚拟目录在同一服务器上运行的WCF服务访问虚拟目录? - How do I access a virtual directory from a WCF service that is not running on the same server as the virtual directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM