简体   繁体   English

asp.net mvc将本地文件添加到Web服务器

[英]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.

相关问题 将数据从本地 excel 文件加载到 ASP.NET MVC web 应用程序以存储在数据库中 - Load data from local excel file to an ASP.NET MVC web app to store in database 将文件写入Web服务器 - ASP.NET - Writing file to web server - ASP.NET 从服务器而不是本地驱动器路径在MVC ASP.NET中加载XML文件 - Loading an XML file in MVC ASP.NET from a server instead of the local drive path Twilio SMS 无法通过部署到 Web 服务器的 ASP.NET MVC C# web 工作(但在本地测试环境中工作正常) - Twilio SMS not working via ASP.NET MVC C# web deployed to Web Server (but works fine in local test environment) 邮件发送代码在本地运行,但在ASP.NET MVC中的服务器上不运行 - Mail sending code works at local but not on server in asp.net mvc 会话ASP.NET MVC上的本地存储或服务器端会话? - Session Local Storage or Server side session at ASP.NET MVC? asp.net mvc 5 cookie不在本地服务器上持久存在 - asp.net mvc 5 cookies not persisting on local server C#Asp.NET内部Web应用程序:从其他本地服务器复制文件 - C# Asp.NET Internal Web App: Copy file from a different local server 如何在不将文件下载到Web服务器的情况下使用asp.net mvc将文件传送到客户端? - How to work with file delivery to the client in asp.net mvc without downloading the files on the web server? 在Asp.net MVC中的图表中显示本地JSON文件数据 - Display local JSON file data in a chart in Asp.net MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM