从Web服务器(ASP.NET)访问文件服务器上的文件夹时出现问题 [英] Problem accessing folder on file server from web server (ASP.NET)

查看:106
本文介绍了从Web服务器(ASP.NET)访问文件服务器上的文件夹时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我了解与从ASP.NET访问文件服务器上的文件夹的权限有关的问题.

我用下面的-
Web服务器-IIS 5.1
文件服务器
ASP.NET 3.5

1.我在Web服务器的IIS中创建了两个虚拟目录.一个保存a)应用程序的文件,另一个保存文件服务器上b)files目录.
2.我在Web服务器和文件服务器上都创建了一个新用户"NEWUSER",并将它们添加到相应服务器的管理员组中.
3.
a)应用程序虚拟目录已检查Windows集成身份验证,禁用了匿名身份验证.
b)文件虚拟目录已为NEWUSER启用匿名访问.
4.
文件服务器上的目录已被授予NEWUSER的完全安全访问权限.我还为NEWUSER共享了此目录.
5.
我在ASP.NET客户端web.config中定义了以下配置.
< pre lang ="xml">& lt;身份验证模式=&"Windows& quot;/& gt;
</pre>

这是我的下面的代码.
__________________________________________________________

Could someone help me understand issues related to permissions in accessing a folder on file server from ASP.NET.

I use the below -
Web Server - IIS 5.1
File Server
ASP.NET 3.5

1. I created two virtual directories in IIS in the web server. One holds the files for the a) application and the other points to b)files directory on the file server.
2. I created a new user "NEWUSER" on both the web server and the file server and added them to corresponding servers'' administrators group.
3.
a) Application virtual directory has windows integrated authentication checked, anonymous authentication disabled.
b) Files virtual directory has anonymous access enabled for NEWUSER.
4.
Directory on file server has been given full security access for NEWUSER. I have also shared this directory for NEWUSER.
5.
I have below configuration defined in ASP.NET client web.config.
<pre lang="xml">&lt;authentication mode=&quot;Windows&quot;/&gt;
</pre>

This is my code below.
__________________________________________________________

<pre>private void PopulateGrid()
    {
        try
        {
            DirectoryPath = @"\\[WEBSERVER]\[filesVirtualDirectory]\" + Convert.ToString(Request.QueryString["ID"]);
            DirectoryInfo currentDirInfo = new DirectoryInfo(DirectoryPath);
            // pass a class object as datasource to gridView object
            fsItems = new List&lt;FilesInfo&gt;();
            if (currentDirInfo.Exists)
            {
                foreach (FileInfo fi in currentDirInfo.GetFiles())
                {
                    FilesInfo fInfo = new FilesInfo();
                    fInfo.Name = fi.Name;
                    fInfo.Extension = fi.Extension;
                    fInfo.FileLink = "//[WEBSERVER]/[filesVirtualDirectory]/" + Convert.ToString(Request.QueryString["ID"]) + "/" + fi.Name;
                    fsItems.Add(fInfo);
                }
            }
            gvFiles.DataSource = fsItems;
            gvFiles.DataBind();
        }
        catch (Exception ex)
        {
            ExceptionLogger.LogError(ex);
        }
    }</pre>

该代码从目录中读取内容,然后填充到网格中.当我在Web服务器上运行应用程序时,Web服务器无法列出目录的内容,但是不会产生任何错误.当我尝试将文档上载到此文件夹时,出现错误-找不到网络路径".我有使用Word interop编写的代码,该代码创建一个文档并将其保存到此文件夹.我在此上收到访问路径被拒绝错误".

当应用程序在我的计算机(本地主机)上运行时,它可以工作.我可以从此文件夹成功上载/删除文档.但是,当应用程序尝试将单词互操作文档保存到此文件夹时,出现一个未知错误.即使从本地主机运行,网页仍引用Web服务器的FilesVirtualDirectory.

有什么想法吗?
谢谢.

The code reads contents from directory and populates on to a grid. When I run my application on the webserver, the web server fails to list contents of the directory, no errors are produced though. When I attempt to upload a document to this folder, I receive an error - "Network Path not found". I have code written using Word interop that creates a document and saves to this folder. I get a "Access to Path denied error" on this.

When the application is run on my machine (localhost), it works. I can successfully upload / delete documents from this folder. I however get an unknown error when application attempts to save the word interop document on to this folder. The web page still refers to webserver''s FilesVirtualDirectory even though it is run from localhost.

Any thoughts?
Thanks.

推荐答案

根据我的经验.即使有Windows凭据,IIS似乎也采取了偷懒的态度,并且变得匿名.

至于是否访问服务器上的文件夹...是否具有Windows凭据,除非您明确模拟了一个用户,否则IIS不会假装它本身(或应用程序池用户)以外的任何人.在这种情况下,您可以进行设置您的应用访问该文件夹时完全不需要用户的信任.

您是否有理由不向该文件夹授予NETWORK SERVICE(或正在运行IIS的任何内容)权限?
Not in my experience. IIS seems to take the lazy way and go anonymous, even if there are Windows creds available.

As far as accessing a folder on the server...Windows credentials or not, IIS won''t pretend to be anyone other than itself (or the app pool user) unless you explicitly impersonate a user, in which case you can set up your app to access the folder without really involving the user''s creds at all.

Is there a reason you can''t give permissions to NETWORK SERVICE (or whatever is running your IIS) to that folder?


您是否检查了IIS用户(IUSR)是否具有写权限是否在目标文件夹上?我认为您需要为IUSR设置完全权限,而不是设置网络服务
Did you check whether your IIS user(IUSR) has write permission on the target folder or not? I think you need to set full permission for IUSR instead of NETWORK SERVICE


解决方案很简单.我忽略了这一点真是太疯狂了.

结论
为了使文件服务器和Web服务器相互通信,必须创建一个公共域用户.我创建的用户不是域用户.他们只是这些服务器上的用户.
The solution is simple. It is crazy that I overlooked this.

Conclusion
In order for the file server and the web server to communicate with each other, a common domain user has to be created. The user that I created was not a domain user. They were users only on those servers.


这篇关于从Web服务器(ASP.NET)访问文件服务器上的文件夹时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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