views:

46

answers:

2

Hopefully this explanation will make sense, but what is the best way (if it is even possible) to pass along user credentials to preform a specific application from an ASP.NET MVC application. Currently I am working on trying to create directories on another server, we can't do this using the generic credentials that the application is running with; however, we have been told that we can if we pass the credentials of the user currently using the application along.

Currently we are running on IIS 6.0 but will be moving to IIS 7.0 in the near future and likewise we are using Integrated Windows authentication for the web applications.

A: 

Yes. You should take a look at User property and the IIS Authenticated methods

Frank
That gives us the user who is currently accessing the site (we are using this for access control), but I'm looking for a way to pass this along to say, Directory.CreateDirectory so that user is preforming the action instead of the network service.
Rob
+1  A: 

Here is a KB article which describes a few ways of doing user impersonation.

Note that some of their examples seem to be using the current authenticated user, but you can obviously adapt this to use whatever user you'd like.

Edit: I've used code very much like in the section "Impersonate a Specific User in Code" to access files on a remote share using the credentials of a user with access to said share. Pretty straight forward.

mmacaulay
Indeed, I just wrote some code into the system and it looks like we might have a winner. However, I am getting an error that "The specified network name is no longer available." when trying to create a directory. Any ideas?
Rob
Can you specify the line giving the error?
Frank
@Frank - The path needs to be censored for obvious reasons but it's just a Directory.CreateDirectory("\\server\directory\new") call.
Rob
Hmm, are you able to do any other file operations? Read directory index, read the contents of an existing file, etc.
mmacaulay
Odd, I just did a DirectoryInfo on the existing part of the path and I'm getting back that it doesn't exist from the code, but no issues actually connecting to it.
Rob
Looks like we are half way to the solution, I've opened up another question with the problems related to the credentials across the network.http://stackoverflow.com/questions/2632556/
Rob

related questions