views:

160

answers:

4

Hey guys,

I'm running into a (hopefully) small issue. I have a web app written in ASP.NET, that will be running off of a Windows 2003 Server machine using IIS 6.0. When I run it locally, it works perfect. When I run it from the server, the site works fine. The issue lies in writing to a remote folder. I have a network folder using AD permissions that the application writes to. With my AD account (when I write it locally) it authenticates properly, but when using the IIS account it does not. Has anyone come across this? Any solutions available?

So far, I've tried using my AD account as the "Guest Account" in IIS that the site runs off of, but that still didn't work.

Any thoughts, explanations, or suggestions would be greatly appreciated!

Thanks.

A: 

Might it be related to the account that the Application Pool is running under?

Jeremy
+3  A: 

By default ASP.NET runs under the context of a local user account, which will not have access to your AD machines. You can reconfigure the connection pool to run as a domain account and lo, it gets access. You should give the domain account as little privileges as possible, and add it to the IIS_WPG on the IIS machine and give it Run as service rights on that box.

blowdart
A: 

You might also consider doing as suggested in this SO answer:

http://stackoverflow.com/questions/1411013/asp-net-windows-authentication-impersonate-problem

Wrap the code that is doing the writing to a remote location and everything else could be left alone. This will give you the best security for the web app since you are only impersonating an account with these writes for the code that needs it instead of all of it.

klabranche
Seeing as how that's my answer ... *grin* I wouldn't do that if at all possible, because (a) it won't work in that case and (b) to make it work you need to hard code a username and password of a domain account to switch context. Which is bad.
blowdart
@blowdart - I am missing something then.... Why wouldn't it work?
klabranche
Well the impersonation in that answer needs windows auth, the person who asked said he switched it to test, not that it's a permanent setting
blowdart
Gotcha.... I thought you meant there was a REAL limitation in that it wouldn't actually work. We have done this as laid out by others in setting the impersonation up at the web.config and in the connection pool for the app but I thought your way is ingenious in that it really limits the security to just that operation. I do agree the username/pwd being hard coded is yucky. :)
klabranche
+1  A: 

The way I normally tackle these situations is to do a couple of steps.

  • In AD create an account for the service.
  • Add this account to the network share you wish to access.
  • Then have your ASP.Net application run using that service account instead of the local IIS account.
  • In your web.config file you put the following line under

    <system.web>
     <identity impersonate="true"/>
    </system.web>

Demetri
Hmmm...I have the account created in AD and I've added the permissions needed on the share. I changed the Application Pool user from "Network Service" to the new AD user. I have also changed the Allow Anonymous account to the AD user account as well. The web.config file was also changed. It will won't write out to that folder. Any thoughts?!
SlackerCoder
Well make sure the setting are applies for you app not at the top level in IIS. Also, under directory security -> Authentication and Access Control -> Edit - Make sure the Integrated Windows Authentication is checked.
Demetri
One more thing to make sure of, is that all errors are being written out to some log. Usually when it fails to write it will throw an error with some info that will probably help.
Demetri