Вызов функции IMNRC происходит не так, как это было в SharePoint 2010. Вот новый код:
some SharePoint ideas
public class Utility
{
public static WindowsIdentity GetWindowsIdentityFromClaimsToken()
{
WindowsIdentity wi = null;
// Run this portion of code as application pool account, so that C2WTS service is called as this account
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Get the UPN value of the user from the UPN claim type
Microsoft.IdentityModel.Claims.IClaimsIdentity identity = ((Microsoft.IdentityModel.Claims.ClaimsIdentity)Thread.CurrentPrincipal.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity);
string upn = null;
foreach (Microsoft.IdentityModel.Claims.Claim claim in identity.Claims.Where(claim => StringComparer.Ordinal.Equals(ClaimTypes.Upn, claim.ClaimType)))
{
upn = claim.Value;
}
if (upn == null)
{
throw new Exception(string.Format("Cannot Impersonate {0} since he doesn't have a UPN in his claims", Thread.CurrentPrincipal.Identity.Name));
}
// Get a WindowsIdentity from the UPN of the user by calling C2WTS service
try
{
wi = Microsoft.IdentityModel.WindowsTokenService.S4UClient.UpnLogon(upn);
}
catch (System.Exception ex)
{
throw new Exception(string.Format("Impersonation failed. Message: {0}", ex.Message));
}
});
return wi;
}
}
using (WindowsImpersonationContext ctxt = Utility2.GetWindowsIdentityFromClaimsToken().Impersonate())
{
ServiceReference.ServiceClient = client = new ServiceReference.ServiceClient();
var resultOptions = new MetadataResultOptions();
resultOptions.Models = ResultType.Identifiers;
var criteria = new MetadataSearchCriteria();
criteria.SearchOption = SearchOption.UserDefinedObjectsOnly;
OperationResult result;
var models = _client.MetadataGet(new International(), resultOptions, criteria, out result);
}
public class LinqToSPSecurity
{
public static void RunWithElevatedPriveledges(SPWeb web, Action<SPWeb> action)
{
Guid webId = web.ID;
Guid siteId = web.Site.ID;
HttpContext backupCtxt = HttpContext.Current;
try
{
if (SPContext.Current != null)
HttpContext.Current = null;
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (SPSite elevatedSite = new SPSite(siteId))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb(webId))
{
HttpRequest httpRequest = new HttpRequest("", elevatedWeb.Url, "");
HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new System.IO.StringWriter()));
SPControl.SetContextWeb(HttpContext.Current, elevatedWeb);
action(elevatedWeb);
}
}
});
}
finally
{
if (SPContext.Current != null)
HttpContext.Current = backupCtxt;
}
}
public static void RunWithElevatedPriveledges(Action<SPWeb> action)
{
RunWithElevatedPriveledges(SPContext.Current.Web, action);
}
}
Пример двухмерного клеточного автомата из 6 состояний (0-5) и с начальным состоянием "1" в топ-центре сетки. Каждому состоянию ...