0
votes

so i've built a web application in asp.net and c#. That web application will be shown in a sharepoint webpage through i a 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?

3
Did you include the reference to Sharepoint in your project references?mituw16
nop, nobody told me i had to. do you know where do i get the dll to add?aconstancio

3 Answers

0
votes

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')
0
votes

Try changing the target platform to x64 and target framework to .NET 3.5 (4.5 if using vs2012 and Sharpoint 2013).

0
votes

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