views:

209

answers:

2

I constantly trip on this when writing apps for our intranet.

Let's say we have a network share called "\\server1\myfolder", and I'm writing an app that needs to read a text file from there. Access to the share is very limited, which is fine. If someone doesn't have access to the folder, the app catches the error and tells the user they don't have access.

This works fine when I run it locally, but when I publish the app to the test server, it never has access to the folder, no matter who is running the app. Ideally the app would impersonate the user and use their credentials, but I never seem to be able to set it up correctly.

My web.config is set up like this:

<authentication mode="Windows"/>
<identity impersonate="true"/>

I've also tried impersonate="false", but it doesn't make a difference. Can someone explain what is going on here, to someone with a very limited knowledge of IIS (this is running on IIS 6 by the way)? Any idea how this should be set up, or is it impossible?

A: 

Check your IIS directory security settings. You need to have anonymous authentication turned off and Windows authentication turned on.

Cam Soper
Those appear to already be the case. "Enable anonymous access" is not checked, and "Integrated Windows authentication" is checked.
gfrizzle
Yep, I had forgotten about what David mentioned. You should look into what he posted.
Cam Soper
+1  A: 

This previous post is similar and contains a valid answer:

http://stackoverflow.com/questions/29346/access-files-from-network-share-in-c-web-app

as does this one

http://stackoverflow.com/questions/1435753/asp-net-access-to-network-share

David Stratton
All I get is "Incorrect Function" when I try to create the System.Security.Principal.WindowsIdentity, no matter what I pass it. I'm definitely passing it my User Principal Name, but it doesn't recognize it.
gfrizzle