我们最近将一个 Web 应用程序移到了一台新机器上。旧的是 Win2k,IIS 6。
新机器是 Win Server 2003,IIS 7。
该应用程序之前在网络共享上查找图像文件,映射为驱动器盘符 O
。这工作正常。
移动后,该应用程序无法再访问这些文件。应用程序中尝试访问 O:
驱动器文件的部分是经过编译的 CGI,因此我不确定它在内部是什么样子。我可能可以访问源代码,但我决定先尝试一个非常简单的测试,看看哪里出了问题。
为了尝试排除故障,我创建了一个小型 C# 程序,它尝试访问本地测试文件(在 C:
驱动器上),然后在 O:< 上查找文件
驱动器,然后是 Z:
驱动器,然后查找与 O:
驱动器上相同的文件,但使用 UNC 路径而不是依赖驱动器映射。最后,它打印出它正在运行的域和用户名。我通过用于注册从旧服务器移出的原始 EXE 的相同方法将其注册为 CGI。
C:
驱动器上的文件读取没有问题,但无法读取其他文件。 C# 应用程序告诉我它正在作为 Traffic
域下的帐户 Washington$
运行。我认为正在使用的帐户是 Washington
(请注意,一个帐户末尾有一个 $
,一个没有)。
在我尝试失败后,我立即以用户身份通过远程桌面登录:Washington
在 Traffic
域上,并且能够看到测试文件在 UNC 路径上没有任何问题(在命令提示符下测试,通过 dir\\trsystem\images2\testFile.txt
。
我不受映射驱动器号的束缚;事实上,我想切换到使用 UNC 路径。
此外,我对 Windows 域和 IIS 管理/管理还很陌生。这个问题可能有一个非常基本的根本原因,我只是不知道或忽略了。
我的程序的输出如下:
--- Success opening C drive file! --- Failed to open O drive file: System.IO.DirectoryNotFoundException: Could not find a part of the path 'O:\testFile.txt'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.OpenRead(String path) at Testing.Main() Failed to open Z drive file: System.IO.DirectoryNotFoundException: Could not find a part of the path 'Z:\testFile.txt'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.OpenRead(String path) at Testing.Main() Failed to open UNC file: System.UnauthorizedAccessException: Access to the path '\\trsystem\images2\testFile.txt' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.OpenRead(String path) at Testing.Main() ---------- ---------- ---------- Domain Name is:TRAFFIC UserName is:WASHINGTON$
And, the program itself (note that this is my first foray into C#; and thrown together based on web examples so please overlook it's uglyness):
using System;
using System.IO;
using System.Security.Permissions;
class Testing{
public static void Main() {
bool cFile = true;
bool oFile = true;
bool zFile = true;
bool uncFile = true;
try{
//Try to open the file on the C drive
File.OpenRead("C:\\testFile.txt");
}
catch (Exception e){
Console.WriteLine("Failed to open C drive file:\n");
Console.WriteLine(e.ToString());
cFile = false;
}
if (cFile)
{
Console.WriteLine("\n\n--- Success opening C drive file! ---\n\n");
}
Console.WriteLine("\n\n");
try
{
//Try to open the file on the O drive
File.OpenRead("O:\\testFile.txt");
}
catch (Exception f)
{
Console.WriteLine("Failed to open O drive file:\n");
Console.WriteLine(f.ToString());
oFile = false;
}
if (oFile)
{
Console.WriteLine("\n\n--- Success opening O drive file! ---\n\n");
}
Console.WriteLine("\n\n");
try
{
//Try to open the file on the Z drive
File.OpenRead("Z:\\testFile.txt");
}
catch (Exception g)
{
Console.WriteLine("Failed to open Z drive file:\n");
Console.WriteLine(g.ToString());
zFile = false;
}
if (zFile)
{
Console.WriteLine("\n\n--- Success opening Z drive file! ---\n\n");
}
Console.WriteLine("\n\n");
try
{
//Try to open the file via UNC
File.OpenRead("\\\\ntsys\\images2\\testFile.txt");
}
catch (Exception g)
{
Console.WriteLine("Failed to open UNC file:\n");
Console.WriteLine(g.ToString());
uncFile = false;
}
if (uncFile)
{
Console.WriteLine("\n\n--- Success opening UNC file! ---\n\n");
}
Console.WriteLine("\n\n");
Console.WriteLine("---------- ---------- ----------\n\n");
string domainName = Environment.UserDomainName;
string userName = Environment.UserName;
Console.WriteLine("Domain Name is:" + domainName + "\n");
Console.WriteLine("UserName is:" + userName + "\n\n");
}
}
提前感谢您提供任何帮助或故障排除想法!
最佳答案
关于windows - IIS 无法访问文件,但通过同一帐户登录的用户可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4852312/