简体   繁体   中英

IIS Cannot access file, but user logged on via same account can

We recently moved a web application over to a new machine. The old one was Win2k, IIS 6.

New machine is Win Server 2003, IIS 7.

The application was previously looking for image files on a network share, mapped as drive letter O . This was working fine.

Upon moving, the app was no longer able to access these files. The portion of the app that tries to access the O: drive files is a compiled CGI, so I'm not sure what it looks like on the inside. I could probably get access to the source, but I decided to try a very simple test to try and see what's wrong first.

To try and troubleshoot, I created a small C# program that tries to access a test file locally (on the C: drive), then looks for a file on the O: drive, then the Z: drive, and then looks for the same file as on the O: drive, but uses a UNC path instead of relying on a drive mapping. Finally, it prints out the domain and username it's running under. I registered this as a CGI via the same method that was used to register the original EXE that got moved over from the old server.

The file on the C: drive is read without problem, but the other files cannot be read. And the C# app tells me it's running as account Washington$ under the Traffic domain. The account I THOUGHT was in use was Washington (note that one has a $ at the end, one does not).

Right after I tried that and got the failures, I logged on via Remote Desktop as User: Washington on the Traffic domain, and was able to see the test file on the UNC path without any problem (tested in a command prompt, via dir \\\\trsystem\\images2\\testFile.txt .

I'm not tied to the mapped drive letters; in fact I'd like to switch over to use the UNC path.

Also, I'm pretty new to Windows domains and IIS management/administration. This problem could have a very basic root cause that I'm just unaware of or overlooking.

The output of my program is below:

--- 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");
    }
}

Thanks in advance for any assistance or troubleshooting ideas!

Why don't you spend some time on Microsoft KB ?

http://support.microsoft.com/kb/257174

IIS does not support mapped drives, so what you see is simply by design.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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