Vijay Verma
12/27/2002 7:12:00 PM
Hi all,
I am developing a webservice that needs to connect to a SqlServer7 database
via namedpipes. I realize that the default ASPNET user does not have
sufficient privileges to achieve this and that I need to use impersonation.
The error that I receive upon accessing the service that uses impersonation
is:
System.InvalidOperationException: An anonymous identity cannot perform an
impersonation.
at System.Security.Principal.WindowsIdentity.Impersonate(IntPtr
userToken, WindowsAccountType acctType)
at System.Security.Principal.WindowsIdentity.Impersonate()
I cannot specify the username and password for the user that I want the
application to impersonate as because of our security considerations.
Could you someone point out what more do I need to do in this regard. In
general, are there any documents over the web that talk about standard
practices for ASP.Net or Webservices hosting?
Thanks in advance,
Vijay
=========================================
Current configuration
1. web.config file
<configuration>
<system.web>
<identity impersonate="true" />
</system.web>
</configuration>
2. The webservice directory is configured for anonymous access
3. Invoke impersonation code before opening the connection:
private void OpenConnection() {
System.Security.Principal.WindowsImpersonationContext
impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
try {
connection = new SqlConnection(sConnectionString);
connection.Open();
} catch (Exception ex) {
LogErrorMessage("Exception", "OpenConnection", "",
ex.Message);
connection = null;
}
impersonationContext.Undo();
}