|
-
Apr 17th, 2003, 11:16 AM
#1
Thread Starter
Lively Member
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:
Response.ContentType = "Application/pdf"
Response.WriteFile("C:\Test\Test.pdf")
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.
-
Apr 18th, 2003, 05:19 PM
#2
Lively Member
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.
-
Apr 21st, 2003, 08:05 AM
#3
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|