简体   繁体   中英

asp.net web forms get sharepoint username

so i've built a web application in asp.net and c#. That web application will be shown in a sharepoint webpage through ia iframe or something, thats not up to me. What i need to finish the project is a way of getting the sharepoint logged in username.

someone there told me it was simple and could be done with this code:

using Microsoft.SharePoint;

SPContext.Current.Web.CurrentUser.LoginName

however i get these errors:

"The type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)"

"The name 'SPContext' does not exist in the current context."

do you guys have any idea of how to solve this or know any other way to do this?

Sounds like you're not running the aspx on the Sharepoint server which is the only way you'd be able to call SPContext to get the currently logged in Sharepoint user.

If you can run custom code on the parent sharepoint page, you could store the LoginName of the current user in the javascript DOM, then access that in your iframe ASP.NET page, assuming that both pages are on the same domain. You could get that loginName in javascript like this:

window.parent.document.getElementById('currentLoginName')

尝试将目标平台更改为x64,将目标框架更改为.NET 3.5(如果使用vs2012和Sharpoint 2013,则为4.5)。

In sharepoint 2013 I have used this.Page.User.Identity.Name and it's work fine for me. Hope can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM