tags:

views:

24

answers:

2

Hello.

I made a simple webpage with asp.net 3.5

and I wrote a code below

var lines = File.ReadAllLines(@"\ad1-sunglim\Share\test.ini");

yes, ad1-sunglim is my PC. and that directory has a file, test.ini. and permission to read.

But everytime I try to execute this code, I got UnauthorizedAccessException.

do I have to impersonate ?

please give me solutions.

thanks in advance.

[[edit]] But my Winform program can read that file without impersonate.

+1  A: 

You need to make sure that the user that is running the website (the application pool identity in IIS 7.x) has the correct permissions to the share.

Additionally, as far as I know, you need to use \\ for UNC paths:

@"\\ad1-sunglim\Share\test.ini"
Oded
A: 

The Winform application worked because it was running under your account, which I assume had access.

If you're using Anonymous Authentication, sites in IIS run under a different account (usually Network Service in II6, IUSER in IIS7), so make sure that account has permission too.

Damien Dennehy