从网络共享在C#中的Web应用程序访问文件 [英] Access files from network share in c# web app

查看:373
本文介绍了从网络共享在C#中的Web应用程序访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要从网络共享读取(和可能写入)文件的Web应用程序。我想知道什么是最好的方式做到这一点会是什么?

I have a web application that needs to read (and possibly write) files from a network share. I was wondering what the best way to do this would be?

我不能给网络服务或ASPNET帐户访问网络共享。我可能使用模拟。

I can't give the network service or aspnet accounts access to the network share. I could possibly use impersonation.

网络共享和Web应用程序都托管在同一域,我可以专门创建的域的新用户用于此目的,但是我不太清楚如何加入创建文件流和指定的点凭据在Web应用程序中使用。

The network share and the web application are both hosted on the same domain and I can create a new user on the domain specifically for this purpose however I'm not quite sure how to join the dots between creating the filestream and specifying the credentials to use in the web application.

不幸的是,驱动器未映射为计算机上的网络驱动器,它只是作为一个网络共享提供给我,所以很遗憾,我不能做一个透明的呼叫。

Unfortunately the drive isn't mapped as a network drive on the machine, it's only available to me as a network share so unfortunately I can't make a transparent call.

有一个问题,我可以模拟想到的......我只能模仿每个应用程序域的一个用户我的认为的,但我很高兴能得到纠正。我可能需要将此文件写入到几个不同的股票,这意味着我可能要模仿多个用户。

There is one problem I can think of with impersonation... I can only impersonate one user per application domain I think but I'm happy to be corrected. I may need to write this file to several different shares which means I may have to impersonate several users.

我想创建一个标志......如果我能做到,我就可以向使用前面为他们的凭据,然后动态地应用的安全性,并给他们有意义的错误消息如果访问被拒绝的想法。 ..我要去演,但我会回来的更新。

I like the idea of creating a token... if I can do that I'll be able to ask the use up front for their credentials and then dynamically apply the security and give them meaningful error messages if access is denied... I'm off to play but I'll be back with an update.

推荐答案

已经拥有域帐户。尝试IIS集成身份验证。你会得到一个丑陋的登录框断网,但你的creds应该向下传递到文件共享。

Given everyone already has domain accounts. Try IIS integrated authentication. You will get an ugly logon box off network but your creds should pass down to the file share.



你是说只有你有烫发的​​共享或您手动将其映射到一个驱动器号。如果以后你可以使用UCN \\主机名\\共享同样的方式,你会使用C:\\ shared_folder。

@lomaxx
Are you saying that only you have perms to the share or that you manually mapped it to a drive letter. If the later you can use ucn \host\share the same way you would use a c:\shared_folder.

随机
难道是共享镜像到主机上的本地文件夹的负担?我听说ROBOCOPY是pretty得心应手。

Random Would it be a burden to mirror the share to a local folder on the host? I hear ROBOCOPY is pretty handy.

另一个想法。你的目标共享运行IIS,您可以通过HTTP读取,如果你需要写调查WebDAV的。

Another Idea. Run IIS on your target share you can read via http and if you need to write investigate webdav.

这篇关于从网络共享在C#中的Web应用程序访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆