Results 1 to 3 of 3

Thread: Problem using WriteFile with files stored on other servers?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    122

    Question Problem using WriteFile with files stored on other servers?

    I have an ASP.NET site in which I need to binary-write the contents of files to the users' browsers rather than linking to the files via the use of URLs. The following example shows how to open a file on a local drive using its physical path and then write the binary contents of the file to the browser:

    VB Code:
    1. Response.ContentType = "Application/pdf"
    2.         Response.WriteFile("C:\Test\Test.pdf")
    3.         Response.End()

    The above code works fine, but if I put the file on a mapped drive (e.g. "G:\Test\Test.pdf"), I get an error which says "System.IO.DirectoryNotFoundException: Could not find a part of the path "G:\Test\Test.pdf".

    If I use the full path to the file, which is on another server (e.g. "\\ServerName\cdrive\Test\Test.pdf"), I get the following error message: "System.IO.IOException: Logon failure: unknown user name or bad password"

    I am able to access the file via Windows Explorer. I believe the problem may have something to do with authentication. Can anyone help me with this?

    Thanks.

  2. #2
    Lively Member
    Join Date
    Aug 1999
    Location
    Amsterdam
    Posts
    117
    You ran into a security issue. First, you have to disable anonymous access to your webapplication in IIS and set identity to impersonate='true' in your web.config. This way you won't access the filesystem as the aspnet user but as the logged on user. Second, the ability to access a remote machine depends on the type of logon session created. And the type of logon session created depends on the type of authentication you configured (in IIS). When specifing 'Windows Integrated' a network loggon session will be created, which has no network credentials and won't be able to acccess a remote machine. (The only way to make this work is to make use of delegation.) When configuring 'Basic Authentication' an interactive logon session is created, which has network credentials, and will be able to access a remote machine. When your workstation is the same as your IIS box it will always work because your (interactive) logon session will be used to authenticate.

    When you use Windows Explorer to browse a remote machine's filesystem your interactive loggon session will be used to authenticate with that machine.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    122
    Thanks! This is a big help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width