L'operazione non è valida a causa dello stato corrente dell'oggetto.(per extranet)
-
10-12-2019 - |
Domanda
Sto usando il seguente codice per impersonare un utente su un extranet che utilizza l'autenticazione basata su modulo, tuttavia quando si tratta di questa linea (SPSite s = new SPSite(siteStr, userToken);)
Generatori IT
.InvalidOperationException.
Ho testato e sappi che gli allusitori [4] esistono.
.string siteStr = "http://mywebSiteUrl/"; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteStr)) { using (SPWeb web = site.OpenWeb()) { SPUserToken userToken = web.AllUsers[4].UserToken; SPSite s = new SPSite(siteStr, userToken); SPWeb w = s.OpenWeb(); myLiteral.Text = "Currently logged in as: " + w.CurrentUser.ToString() + "( " + w.CurrentUser.Name + ")"; } } });
Soluzione 2
The problem solved when You add the user to the site under site setting -> people and groups
Altri suggerimenti
Can you try following, I have just kept new SPSite and SPWeb object outside RunWithElevatedPrivileges
string siteStr = "http://mywebSiteUrl/";
SPUserToken userToken;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteStr))
{
using (SPWeb web = site.OpenWeb())
{
userToken = web.AllUsers[4].UserToken;
}
}
});
SPSite s = new SPSite(siteStr, userToken);
SPWeb w = s.OpenWeb();
myLiteral.Text = "Currently logged in as: " + w.CurrentUser.ToString() + "( " + w.CurrentUser.Name + ")";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange