0
votes

There is sharepoint 2003. Developed Web part.

When a user accesses a web part, then passes authentication on the server side.

I need within the Web part to send a request to Web app. When I send a request to the server where it is deployed Web app, trying to login server account where the deployed Web part.

And I need that when i send a request to the server where it is deployed Web app used to authenticate the user account that accesses the Web part.

Authentication Type: NTLM

How Web part can turn to Web app of the user name that accessed the Web part?


Found two possible solutions:

1.Add Web.config in WebPart with the following contents:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <authentication mode="Windows" />
    <identity impersonate="true" />
  </system.web>
</configuration>

It does not help. It is not clear why.

2.Use the following code:

        WindowsIdentity winId = (WindowsIdentity)Context.User.Identity;
        WindowsImpersonationContext ctx = null;

        try
        {
            // Start impersonating.
            ctx = winId.Impersonate();
            // Now impersonating.
            // Access resources using the identity of the authenticated user.
            _autocompleteService.SendParametersForAutoComplete(_loger,
                        new KeyValuePairString("performerId", performerId),
                        new KeyValuePairString("templatePath",
                                                StringConverter.EncodeToURL(templatePath)),
                        new KeyValuePairString("specificationId", specificationId),
                        new KeyValuePairString("buyerId", buyerId),
                        new KeyValuePairString("performerCompanyId", performerCompanyId),
                        new KeyValuePairString("reestrItemId", reestrItemId),
                        new KeyValuePairString("sessionId", sessionId));
        }
        // Prevent exceptions from propagating.
        catch
        {
        }
        finally
        {
            if (ctx != null) ctx.Undo();
        }

This code is taken on the link: http://msdn.microsoft.com/en-us/library/aa480475.aspx

It does not help. It is not clear why.

In what could be the reason in both cases?

1

1 Answers

0
votes

found the answer - why does not work the second variant.

When you Impersonate a user, you can access local resources as that user, but not remote resources.

How can I solve the problem using the first option?