R – Accessing SharePoint authentication information from .NET ActiveX control

activexauthenticationcookiessharepointweb services

We have a .NET ActiveX control which is embedded inside a custom SharePoint page.
The user has to authenticate (Windows Authentication not Forms Authentication) to access this page.

Our ActiveX control is making web service calls back to the SharePoint server. Because the SharePoint server does not allow anonymous access, we need to provide credentials as part of the web services call. If the user is checking the 'Remember Password' checkbox when prompted for credentials, then we can access those credentials via the CredentialCache.DefaultNetworkCredentials. However, if they do not check that checkbox, we need another mechanism to get a hold of valid credentials (which must exist since we are embedded in a page that can only be accessed via authentication).

How can we access the credential information (probably stored in a cookie) we need to authenticate against SharePoint so we can access the web services?

Best Answer

There is a method in the SPUtility class called EnsureAuthentication, you can also hit the /_layouts/Authenticate.aspx page to log the user automatically in sharepoint.

You can also encapsulate your call with Impersonation.