Multimobile Development: Building Applications for any Smartphone
.NET security and Network Shares
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.security.


Jim Thomas
I have a site that needs to serve various images from a
set of network shares. When a file is requested, backend
C# code looks up the file in SQL server, then loads it
from the path specified and returns it in the response
object with the proper content type.

This all works fine as long as the file is located on a
local drive. As soon as I change the SQL server entry to
point to a file on a network share (which is mapped to a
local drive letter), it fails. I get the following error:

System.IO.DirectoryNotFoundException:
Could not find a part of the path "X:\test.jpg"

I have tried several things to get this to work. I have
changed the ASP.NET process to run as system, and also as
a specific user that I created. All to no avail.

It is running on a ASP.NET development machine, not under
IIS 6. But, I'm not sure if that matters.

Any help would be greatly appreciated.

Thanks,
Jim

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Jim Thomas
I have some more information about this problem:

The following is in one of my .aspx files.

try {
FileIOPermission perm = new FileIOPermission
(FileIOPermissionAccess.Read,@"X:\\");
perm.Demand();
s = (System.IO.Stream)File.OpenRead(name);
} catch (Exception e) {
string    err = e.ToString();
}

The perm.Demand() call does not throw an exception,
indicating that read accesss to the mapped drive (X:) is
permitted. However, on the next line, the call to
File.OpenRead throws a DirectoryNotFound exception as
described in my previous post.

Can someone at Microsoft please help me explain this???

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
leo lin[MS]
Hi Jim Thomas,

Can you give me more details about reproduce procedure?

I try to use normal C# application and visit network map drive, it is work
correctly.

new FileIOPermission(FileIOPermissionAccess.Read ,
"somefile");

// Try to access a file
try {
fs = new FileStream("somefile", FileMode.OpenOrCreate);
}
        catch (Exception e)
        {
            string    err = e.ToString();
        }

Best Regards

leolin
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
leo lin[MS]
Hi Jim Thomas,

Can you give me more details about reproduce procedure?

I try to use normal C# application and visit network map drive, it is work
correctly.

new FileIOPermission(FileIOPermissionAccess.Read ,
"somefile");

// Try to access a file
try {
fs = new FileStream("somefile", FileMode.OpenOrCreate);
}
        catch (Exception e)
        {
            string    err = e.ToString();
        }

Best Regards

leolin
Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
    
Jim Thomas
I've attached a small file that reproduces the problem.

Thanks again,
Jim

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
New book project – Multimobile Development: Building Applications for any Smartphone
Dive into HTML5
 
    
leo lin[MS]
It will be ASPNET user account (aspnet_wp.exe ) can't access network
sharing resource.
ASPNET is local account and it is not domain account.

There is KB Q317012 outlines the security settings for asp.net page.

He has several options:

1. Enabling Delegation.

2. machine.config

a. you can specify either localsystem, asp worker process account or a
specific user account.

b. if you specify the asp work process account, you'll need to enable
the
guest account on the file server to have an

anonymous user access the share.

3. web.config - turn impersonation on or off and then based on the
impersonated
user provide access to the share.

INFO: Process and Request Identity in ASP.NET [aspnetkb]ID:
Q317012

ASP.NET Does Not Work with ASPNET Account on Domain Controller[aspnetkb]
ID: Q315158

Best Regards

leolin

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Jim Thomas
Sorry for the delay, I was on vacation...

Thanks for the response. This code is running in a .aspx
file on my .NET development web server. This is some
kind of an issue with ASP.NET security I think.

Thanks for your help,
Jim

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Steve Jobs’ thoughtful/thought provoking Thoughts on Flash…
Handy list of countries in CSV format
 
    
Frank Tien
Did someone solve this issue? Currently, I also have same problem, so what is the solution of this?
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Frank Tien
Did someone solve this issue? I have the same problem. Please post any possible work around solution.
thx

--------------------------------
From: Frank Tien
Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.IO.DirectoryNotFoundException
System.IO.File
System.IO.FileMode
System.IO.FileStream
System.IO.Stream
System.Security.Permissions.FileIOPermission
System.Security.Permissions.FileIOPermissionAccess




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734