November 15, 2013 Leave a comment
Man, it’s been awhile since I lasted did a post. There have been a lot of changes. I have a new job and am doing consultant work now. I’m diving much more into SharePoint 2013. In fact, I am taking the 70-331 exam this month, so that should be a good step up for my bag of certifications. Anywho..
I had a requirement where I needed to grab the current user and pass the username off to another web application. How I got it to work was to embed the web application in a SharePoint app which just consisted of a web application page. All you need to do is:
1. Start up Visual Studios -> New -> Project -> SharePoint Empty Project (2013)
2. Then right click the Project -> Add -> New Item -> Application Page.
3. From here, make your application page the same page that you want to embed, carrying over any supporting files.
4. Make sure from here the application page runs correctly (taking note that there is no credential passing yet)
5. Add a reference to Microsoft.SharePoint to your project.
6. Then, let’s assume your app page is called Default. You want to edit your .aspx.cs file
Also add on Default.aspx.cs:
SPWeb theSite = SPControl.GetContextWeb(Context);
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;
Now you have control over the SPContext, so you can use that to pass objects off to the web application you need it to be.