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.

2 Answers 2


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


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;


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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