简体   繁体   English

上传和下载文件 ASP.NET C# IIS7

[英]upload and download files ASP.NET C# IIS7

My requirement is, User uploads an excel file, i need to process that excel and store required info in DB and create new excel with required data for user on his computer.我的要求是,用户上传 excel 文件,我需要处理 excel 并将所需信息存储在数据库中,并在他的计算机上创建新的 excel 和用户所需的数据。

I used fileupload control.我使用了文件上传控件。 I have created a folder in my application to store uploaded files.我在我的应用程序中创建了一个文件夹来存储上传的文件。 Once the user uploaded a file, i am taking that file and storing it in my application folder.用户上传文件后,我将获取该文件并将其存储在我的应用程序文件夹中。 Then I am processing it.然后我正在处理它。

Now my user needs to save new excel file on his computer.现在我的用户需要在他的计算机上保存新的 excel 文件。 For this, i provided a textbox for user to enter path where to store the new file.为此,我提供了一个文本框供用户输入存储新文件的路径。

everything is fine while running in VWD.在 VWD 中运行时一切正常。 But when i am running website using IIS7, i got few probs.但是当我使用 IIS7 运行网站时,我遇到的问题很少。

1) fileupload error: User has no access to create a file in my application folders. 1) 文件上传错误:用户无权在我的应用程序文件夹中创建文件。

2) IIS says destination directory does not exist. 2) IIS 表示目标目录不存在。 Because IIS cannot read the directory path on client computer.因为 IIS 无法读取客户端计算机上的目录路径。

I think both are some authentication issues.我认为两者都是一些身份验证问题。

Please guide me on this.请指导我。 If you have the other way in doing this please suggest如果您有其他方式这样做,请建议

Thanks谢谢

For the upload of the file you just have to give your application's identity permission to modify the contents of your upload folder.对于文件的上传,您只需授予应用程序的身份权限即可修改上传文件夹的内容。 You can do this either using the identity impersonate tag in your web.config and putting a user that has rights to modify or by giving the user of your application pool rights to modify your application's folder.您可以使用 web.config 中的身份模拟标签并设置有权修改的用户或授予应用程序池的用户修改应用程序文件夹的权限来执行此操作。

As for the download, you cannot create folders in an arbitrary directory on the user's computer across the internet.至于下载,您不能在互联网上的用户计算机上的任意目录中创建文件夹。 You can only access things inside the sandbox of the user's computer.您只能访问用户计算机沙箱内的内容。 If you were able to modify anything on the user's computer think of the security whole you would have created.如果您能够修改用户计算机上的任何内容,请考虑您将创建的安全整体。 What I would do is create the excel file and then stream it down to the user and then when the dialog pops up they can choose where to save the file to.我要做的是创建 excel 文件,然后创建 stream 给用户,然后当对话框弹出时,他们可以选择将文件保存到的位置。

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

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