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

给你一囗甜甜゛ 提交于 2019-12-03 00:42:06

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.

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.

When it works in debug, is that being used in SharePoint?

Your page and the Sharepoint site might as well be on different servers as far as authentication is concerned -- in order to get the information over you might need to pass it via the QueryString from the webpart if you can -- or you might need to make your own webpart to do this (just put an IFRAME in the part with the src set to your page with the QueryString passing the username).

It does seem that this would be a security issue if you use the name for anything though -- if you are just displaying it, then it's probably fine.

If you actually need to be authenticated, you might need to add authentication into the web.config of the site hosting your standalone page.

edit: I think you'd have better luck putting your page on the same port and server as SharePoint.

I suspect you will have a hard time specifically querying SharePoint for the currently authenticated username. I can't think of a way to easily access the SharePoint context from a separate web application like you are describing.

I don't know what kind of authentication scheme you are using, but you may want to consider using Kerberos, as I've found that it can make these kinds of scenarios a little easier by allowing for delegation and passing credentials from application to application or server to server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!