如何使用c#访问/读取远程位置文件? [英] How to access / read remote location files using c#?

查看:91
本文介绍了如何使用c#访问/读取远程位置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#访问/读取远程位置文件?

How to access / read remote location files using c#?

推荐答案

您收到一条拒绝访问消息,因为您的ASP.NET代码运行的用户帐户没有有权访问任何网络共享。



进入IIS管理器,进入运行代码的应用程序池并更改其使用的帐户。



您必须使用某个域帐户,其中您的IIS服务器和托管您希望信任的共享的服务器。通常,计算机和用户帐户位于同一个域中。必须专门设置此用户帐户,并具有访问网络共享和作为服务登录的权限。
You get an Access Denied message because the user account your ASP.NET code runs under does not have permissions to access any network shares.

Go into IIS Manager, into the Application Pool that is running your code and change the account it's using.

You have to use some domain account where your IIS server AND the server hosting the share that you want to get to trusts. Usually, the machines and user account are in the same domain. This user account must be specifically setup with permissions to access the network share and login as a service.


通过UNC访问它。



Access it via a UNC.

System.IO.FileStream stream = System.IO.File.OpenRead("\\servername\sharename\path\file.txt");





如果此代码在asp.net下运行,然后您需要将匿名用户帐户更改为具有所需访问权限的域帐户,因为默认帐户无法访问网络。



If this code is running under asp.net then you'll need to change the anonymous user account to a domain account that has the desired access as the default account can't access the network.


这篇关于如何使用c#访问/读取远程位置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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