[英]asp.net mvc add local file to web server
I'm working on a ASP.Net MVC application. 我正在研究ASP.Net MVC应用程序。 In my project, I have a third party JavaScript library which dynamically saves data in a xml format.
在我的项目中,我有一个第三方JavaScript库,该库以xml格式动态保存数据。 Using some C# server code, I read this xml data and save it to a local file on my computer.
使用一些C#服务器代码,我读取了该xml数据并将其保存到计算机上的本地文件中。
I will then need to load this said data using the same JavaScript library as before. 然后,我将需要使用与以前相同的JavaScript库加载上述数据。 The library has a load function which, will load xml data from a http URL (cannot give it a local file path)
该库具有加载功能,该功能将从http URL加载xml数据(无法为其提供本地文件路径)
My question is how do place my file on a local server, so I may call an http URL of the file? 我的问题是如何将文件放置在本地服务器上,因此我可以调用文件的http URL?
Here is the question I had posted on the third party tool's forum: 这是我在第三方工具论坛上发布的问题:
http://forum.dhtmlx.com/viewtopic.php?f=6&t=37252&p=115601#p115601 http://forum.dhtmlx.com/viewtopic.php?f=6&t=37252&p=115601#p115601
Any help would be appreciated, thanks! 任何帮助,将不胜感激,谢谢!
the javascript function: javascript函数:
scheduler.load("http://localhost/Tasks.xml", "xml");
Error: 错误:
You can't read a file directly from javascript for security reasons. 出于安全原因,您不能直接从javascript中读取文件。 Browsers shouldn't let you access a file directly from disk.
浏览器不应让您直接从磁盘访问文件。
You can put the file inside an IIS or other web server and access the URL. 您可以将文件放入IIS或其他Web服务器中,然后访问URL。
For example: copy the file to C:\Inetpub\wwwroot\YourFile.xml
Access from http://localhost:80/YourFile.xml
Test in a web browser before you test from the API to make sure that the file is accessible. 在通过API进行测试之前,请先在网络浏览器中进行测试,以确保可以访问该文件。
You should create a controller action that reads the local file and returns it, after appropriate security checks. 在进行适当的安全检查之后,您应该创建一个控制器操作来读取本地文件并将其返回。 Then in your Javascript you use the URL of the controller/action.
然后,在Javascript中,使用控制器/操作的URL。
The proper place to save files in a web application is inside the App_Data
directory. 在Web应用程序中保存文件的正确位置是
App_Data
目录中。 If you update files anywhere else in the web application's directory it will cause a restart of the site (and an app pool recycle). 如果您在Web应用程序目录中的其他任何位置更新文件,则将导致站点重新启动(并回收应用程序池)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.