I have this in a webpart inserted into a page from Sharepoint Admin Site (http://sharepointserver:port) and I want to read some info from mysite:
SPUserToken objSPUserToken = SPContext.Current.Site.SystemAccount.UserToken;
//SPUserToken objSPUserToken = SPContext.Current.Web.CurrentUser.UserToken;
using (SPSite mainSite = new SPSite("http://sharepointserver/sites/mysite", objSPUserToken))
{
SPWeb mainWebSite = mainSite.OpenWeb();
SPListItemCollection listItemsP = mainWebSite.Lists["Pages"].Items;
}
When I run it from Visual Studio, asks for user/password and executes normally, but when I publish the wsp and run it from browser, I have the message: Sorry, this site hasn't been shared with you
I've tried with the CurrentUser (commented line) and it gaves me the same message even from Visual Studio.
I'm sure that the user has rights into mysite, Do you have any idea of what´s happening?
Thanks!