I'm stuck on my project. I have Web Forms published in IIS that are shown in SharePoint 2010 site.

From that Web Form, I want to show the current user in SharePoint.

My solution is from [http://www.sharepointdeveloperhq.com/2009/04/how-to-programmatically-impersonate-users-in-sharepoint/][1] but it is not working for me.

I tried changing the target framework to framework 3.5 and tried changing platform to x64bit.

But it is still not working and is showing a lot of errors. My current code:

using Microsoft.SharePoint;

        string username;
        string sspURL = @"Sharepoint URL";
        SPSite site = new SPSite(sspURL);
        SPWeb web = site.OpenWeb();
        SPUser user = web.CurrentUser;
        username = user.LoginName;
        site.AllowUnsafeUpdates = true;

Error: The Web application at "my url" could not be found.

What am i doing wrong?

note: visual studio is running in the same server where sharepoint is installed with user administrator

  • 1
    Which error you are getting? Because it will run by x64bit platform. – Viraj Gorajia Apr 16 '16 at 7:21

Your website is running outside of SharePoint and as such does not have SharePoint context. It knows nothing about anything going in SharePoint. I

f you instantiate a new SPSite object from outside SharePoint in another site (running on the same server), whatever user the AppPool (or if impersonated, the user opening the webforms site), the current user would become the AppPool account of the user logged into the webforms site.

If the AppPool account does not have permissions on the SharePoint web app / site collection or site you are tying to open, it will fail.

But getting whoever is currently logged on is not possible, it does not matter if you are displaying the webforms site in SharePoint through say a pageviewer, thee 2 sites are logically (and physically) completely separate entities, running in their own memory spaces

|improve this answer|||||
  • + the AppPool account would need SQL permissions to get access to the SharePoint content. – Evariste Apr 16 '16 at 11:01
  • i wonder why, but infopath forms can do that. webforms cant. if its not possible. can any one suggest a better solution. where i can communicate to the currently logged user in sharepoint site. i just want to manage the sql current database. the company i work has a lot of request and demand to the application where the external list cant do. – listojay Apr 17 '16 at 15:07

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.