Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying the current authenticated Sharepoint user from an asp.net Page Viewer Web Part

I am creating a standalone asp.net page that needs to be embedded into a sharepoint site using the Page Viewer Web Part. The asp.net page is published to the same server on a different port, giving me the URL to embed.

The requirement is that after a user is authenticated using Sharepoint authentication, they navigate to a page containing the asp.net web part for more options.

What I need to do from this asp.net page is query Sharepoint for the currently authenticated username, then display this on the page from the asp.net code.

This all works fine when I debug the application from VS, but when published and displayed though Sharepoint, I always get NULL as the user.

Any suggestions on the best way to get this to work would be much appreciated.

like image 662
BenB Avatar asked Sep 22 '08 01:09

BenB


2 Answers

If you want to retrieve the currently authenticated user from the SharePoint context, you need to remain within the SharePoint context. This means hosting your custom web application within SharePoint (see http://msdn.microsoft.com/en-us/library/cc297200.aspx). Then from your custom application reference Microsoft.SharePoint and use the SPContext object to retrieve the user name. For example:

SPContext.Current.Web.CurrentUser.LoginName

You can still use the Page Viewer Web Part to reference the URL of the site, now located within the SharePoint context.

like image 159
Alex Angas Avatar answered Sep 21 '22 12:09

Alex Angas


Thanks heaps for the answers!

Turns out that as long as the asp.net page is using the same URL and port as the Sharepoint site, authentication works across both sites.

The solution is to use a Virtual Directory inside of the sharepoint site and install the asp.net page there.

like image 45
BenB Avatar answered Sep 20 '22 12:09

BenB