下载网络文件 [英] Download Network File
问题描述
下午好,
在Web应用程序中实现了一个方法,该方法接收数据文件中位于文件服务器中的任意长度文件的完整路径,并映射到网络驱动器,该路径检查文件是否存在以及是否通过打开窗口下载来检查文件是否存在.这是代码:
Good afternoon,
Implemented a method in a web application, which receives the full path where the file of any length, is located in the data server, mapped to a network drive, which checks if the file exists and if so by forcing open a window download. Here is the code:
//A cell of the grid selected returns the string "Z:\Test\Apae Analytical Balance.pdf"
FileInfo file = new FileInfo (grvConsulta.SelectedRow.Cells [17].Text);
if (file.Exists)
{
Response.Clear();
Response.AddHeader ("Content-Disposition", "attachment; filename =" + file.Name);
Response.AddHeader ("Content-Length ", file.Length.ToString());
Response.ContentType = "application / octet-stream";
Response.Flush();
Response.WriteFile (file.FullName);
Response.End();
}
else
{
ScriptManager.RegisterStartupScript (this, this.GetType (), "ExibirMensagem", "alert (''" + HttpUtility.HtmlDecode ("File not located in the know.") + "'');", true);
}
问题是运行该应用程序的本地主机,该文件已找到并被要求正常下载,但是从测试服务器在IIS中发布站点后,找不到该文件,并且IIS服务器与数据库服务器不同,并且与映射数据服务器正确. ''尝试在web.config和Data目录中添加密钥,但是问题仍然存在.
有解决这个问题的想法吗?
预先谢谢您.
The problem is that localhost running the application, the file is located and requested to download normally, but after publishing the site in IIS from a test server, the file is not found, and the IIS server is not the same database server and is with the mapping data server correct. ''ve tried adding a key in the web.config with the Data directory, but the problem persists.
Any ideas to solve this problem?
Thank you in advance.
推荐答案
已通读本文,其中介绍了一些最佳实践和可能遇到的问题
http://support.microsoft.com/kb/207671 [
Have a read through this article which describes some best practices and problems you may run into
http://support.microsoft.com/kb/207671[^]
Do not use drive letters mapped to network shares. Not only are there only 26 potential driver letters to select from, but if you try to use a drive letter that is mapped in a different security context, problems can occur. Instead, you must always use Universal Naming Convention (UNC) names to access resources. The format must look similar to the following: \\MyServer\filesharename\directoryname\filename
Mapped drives are user-profile based, so unless the security context you are running your IIS application as on the test server explicity has this drive mapping, it''s not going to understand what Z:\ is.
这篇关于下载网络文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!