Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

C# open file on windows share

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
P4trykx - 07 Aug 2007 11:15 GMT
Hello

I hace a code that opens a file on a windows share.

\\comp1\folder1\file.txt

Folder1 has full access for Everyone. I can open it from explorer on
my computer (my user isn't on set the server). However when I run this
code

FileStream file = new FileStream(serverFilePath, FileMode.Open);

from asp code as the same user as I do it form explorer I get
IOException saying that the user and password are wrong. Howto
convince C# not to login ?

--
Patryk
Andrew Brook - 07 Aug 2007 12:00 GMT
does this work?
System.IO.FileStream fs = new
System.IO.FileStream(serverFilePath,System.IO.FileMode.Open,System.IO.FileAccess.Read);

Andrew

> Hello
>
[quoted text clipped - 14 lines]
> --
> Patryk
P4trykx - 07 Aug 2007 12:39 GMT
> does this work?
> System.IO.FileStream fs = new
> System.IO.FileStream(serverFilePath,System.IO.FileMode.Open,System.IO.FileA?ccess.Read);

no, I get the same Exception

--
Patryk
Kevin Spencer - 07 Aug 2007 12:35 GMT
Hi Patryk,

All processes run in the context of a logged-in user account. If you want to
open a file on another computer, your application must be running in the
context of a user that has permissions to open files on that machine. You
can do this with Impersonation.

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

> Hello
>
[quoted text clipped - 14 lines]
> --
> Patryk
P4trykx - 07 Aug 2007 13:04 GMT
> All processes run in the context of a logged-in user account. If you want to
> open a file on another computer, your application must be running in the
> context of a user that has permissions to open files on that machine. You
> can do this with Impersonation.

Ok, so how does the explorer manage to open this file ?

--
Patryk
Aidy - 07 Aug 2007 14:18 GMT
Explorer is running as the logged on user, your asp.net code is running
under an account local to the machine that has no access rights to any other
machine on the network, so it cannot access files on shares.  You can change
the account your anonymous users run as via the iis admin tools and set it
to an account with the appropriate permissions.

>> All processes run in the context of a logged-in user account. If you want
>> to
[quoted text clipped - 6 lines]
> --
> Patryk
P4trykx - 07 Aug 2007 14:46 GMT
> Explorer is running as the logged on user, your asp.net code is running
> under an account local to the machine that has no access rights to any other
> machine on the network,

But I'm logged as user12 and the same user is in web.config in
impersonate section

<identity impersonate="true" userName="user12" password="somePassowrd"/

There is no users12 on the server(comp1) with the files I want to
access.  \\comp1\folder1\file.txt

--
Patryk

--
Patryk
Kevin Spencer - 08 Aug 2007 12:08 GMT
Are you logged in to a domain (Active Directory) account?

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

>> Explorer is running as the logged on user, your asp.net code is running
>> under an account local to the machine that has no access rights to any
[quoted text clipped - 14 lines]
> --
> Patryk
P4trykx - 08 Aug 2007 12:47 GMT
> Are you logged in to a domain (Active Directory) account?

No, I have a local account.However computer on which I have the
share's is a aomain controller.

I suspect that explorer first tries to accesses the share using logged
user ant if this fails (no such user on the remote computer) it
connects using Guest account.

--
Patryk

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.