Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm developing an asp.net web application and hosted on IIS 7.5 server. These applications are used in sharepoint 2010 using the page viewer web part.

Now I want to get the sharepoint's current user and url in asp.net web application. I checked for solutions but they all need me to deploy my asp.net web application in sharepoint 2010, but I don't want to do that.

I just want to use the page viewer webpart to get aspx pages in sharepoint.


Thanks for the response by Marcin. I tried the following code, but its not working. i jusr get the unhandled error exception:

Object reference not set to an instance of an object.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;

namespace getuser
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string accManager;
            SPUser user1 = SPContext.Current.Web.CurrentUser;
            TextBox2.Text = user1.ToString();
            string sspURL = "mysiteurl....";
            SPSite site = new SPSite(sspURL);
            SPWeb web = site.OpenWeb();
            SPUser user = web.CurrentUser;

            accManager = user.Name;

            if (accManager != "")
             TextBox1.Text = accManager;
       }
    }
 }

I hosted this page on IIS and used the url in page viewer webpart to show in sharepoint 2010. I need to get the current sharepoint user ,url and need to pass query string from sharepoint url to the aspx page and should return url to sharepoint with parameters for another page.

share|improve this question
add comment

migrated from stackoverflow.com Aug 15 '11 at 20:30

This question came from our site for professional and enthusiast programmers.

2 Answers

You cannot access the current SharePoint user information from an external web site. The page viewer web part will only include your ASP.Net page in an iFrame. The SharePoint Authentication will not be passed through.

To get the URL you should be able to parse the http-referrer. That should be the surrounding SharePoint page's url.

To receive the user information you could either write your own page viewer webpart, that passes that information along or use some JavaScript approach

share|improve this answer
add comment

I don't know if this web part "passes" SP context, but you can try using:

SPWeb web = SPControl.GetContextWeb(Context);
SPUser sUser = web.CurrentUser;

or:

SPUser user = SPContext.Current.Web.CurrentUser;

If these values are empty/null, you can pass site or web url as parameter in site url. In asp.net you can open this and get user. I'm not sure it this will work "outside" SP.

Edit: This won't work outside of SP. You can't get context in WinForms/Console apps, etc.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.