从 asp.net 页面查看器 Web 部件显示当前经过身份验证的 Sharepoint 用户
我正在创建一个独立的 asp.net 页面,需要使用页面查看器 Web 部件将其嵌入到共享点站点中。 asp.net 页面发布到同一服务器的不同端口上,为我提供了要嵌入的 URL。
要求是,在使用 Sharepoint 身份验证对用户进行身份验证后,他们导航到包含 asp.net Web 部件的页面以获取更多选项。
我需要在这个 asp.net 页面上执行的是查询 Sharepoint 以获取当前经过身份验证的用户名,然后通过 asp.net 代码将其显示在页面上。
当我从 VS 调试应用程序时,这一切都工作正常,但是当通过 Sharepoint 发布和显示时,我作为用户总是得到 NULL。
任何有关使其发挥作用的最佳方法的建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我怀疑您将很难专门查询 SharePoint 以获取当前经过身份验证的用户名。 我想不出一种方法可以像您所描述的那样从单独的 Web 应用程序轻松访问 SharePoint 上下文。
我不知道您正在使用哪种身份验证方案,但您可能需要考虑使用 Kerberos,因为我发现它可以通过允许委派和在应用程序之间传递凭据来使此类场景变得更容易或服务器到服务器。
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.
如果要从 SharePoint 上下文中检索当前经过身份验证的用户,则需要保留在 SharePoint 上下文中。 这意味着在 SharePoint 中托管您的自定义 Web 应用程序(请参阅 http://msdn.microsoft.com/en-us/library/cc297200.aspx)。 然后从自定义应用程序引用 Microsoft.SharePoint 并使用 SPContext 对象检索用户名。 例如:
您仍然可以使用页面查看器 Web 部件来引用现在位于 SharePoint 上下文中的网站的 URL。
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:
You can still use the Page Viewer Web Part to reference the URL of the site, now located within the SharePoint context.
非常感谢您的回答!
事实证明,只要 asp.net 页面使用与 Sharepoint 站点相同的 URL 和端口,身份验证就可以跨两个站点进行。
解决方案是使用共享点站点内的虚拟目录并在那里安装 asp.net 页面。
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.
当它在调试中工作时,是否在 SharePoint 中使用?
就身份验证而言,您的页面和 Sharepoint 站点可能位于不同的服务器上 — 为了获取信息,您可能需要通过 Web 部件中的 QueryString 传递信息(如果可以的话) — 或者您可能需要制作您自己的 Web 部件来执行此操作(只需将 IFRAME 放入将 src 设置为您的页面并使用传递用户名的 QueryString 的部件中)。
如果您使用该名称进行任何操作,这似乎确实会成为一个安全问题 - 如果您只是显示它,那么可能没问题。
如果您确实需要进行身份验证,则可能需要将身份验证添加到托管独立页面的站点的 web.config 中。
编辑:我认为您最好将页面放在与 SharePoint 相同的端口和服务器上。
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.