0

I have two webapplications and different site collections. I have to move data from One wbapplication site to another.

I used SPSecurity.RunWithElevatedPrivileges.Data's are moving in webapplication1 to Wepapplication2.

But user does not have permisiion for webapplication 2 But the user able to move data to webapp1 to webapp2.

If I remove SPSecurity.RunWithElevatedPrivileges user not able to move the data. If I gave permission for webapp2 is able to move.

So I used SPSecurity.RunWithElevatedPrivileges and it was working in local.

This same funtionality we installed in Client server. when user move data from webapp1 to webapp2 it was showing you dont have access to site.

But it was working in Local sharepoint server.

Client they are having multi server and Webapplication2 is Extented web application

so my doubt is Local sharepoint server it was working But in client server is not working Why its happening ?

my code:

SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite destSite = new SPSite("http://testsite/")) //second webapplication { using (SPWeb destWeb = destSite.OpenWeb()) {

                       //SPSecurity.CatchAccessDeniedException = false;
                       destWeb.AllowUnsafeUpdates = true;
                       if (ContractArea == "UESC BOA Contracts")
                       {
                           destDocumentList = destWeb.Lists.TryGetList("UESC BOA  BP1");
                       }
                       else
                       {
                           destDocumentList = destWeb.Lists.TryGetList("BP1");
                       }

} }

0

When you are running under the ElevatedPrivledges you are running effectively under application pool account of the iis site. Maybe on client site those 2 applications are running under different application pool account there fore WebApp1 code (appPoolA) doesn't have access to the WebApp2.

  • in local my WebApp1 and WebApp2 appPoolA accounts are same.Client system it is different so for this what i can do ? – Elina Jan 12 '17 at 13:20
  • You need to grant contribute or admin permission for the AppPoolA in the WebApp2 (either for whole web app through central admin, or through site collection settings) – Marek Sarad Jan 12 '17 at 13:31
  • Its not possible to get access through code ? – Elina Jan 12 '17 at 13:38
  • For example Wepapp1 - appPoolaccount username - user1 Wepapp2 - appPoolaccount username - user2 so in webapp2 i have to give permission for user1 ? if yes where should i can give?Wepapp2-->Site settings-->site collection administrator i need to add the user1.? – Elina Jan 12 '17 at 13:42
  • Yes it is possible, instead of running with elevated you need to impersonate WebApp2 Pool. Have a look at this example sharepointdeveloperhq.com/2009/04/… . Impersonation is best practice anyway, you need to run code under elevated privileges only if you need to work with local filesystem (ie. make modifications to the web.config or create custom log file) – Marek Sarad Jan 12 '17 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.