public virtual PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "Page" }), "webPartManager"); } HttpRequest requestInternal = page.RequestInternal; if (requestInternal == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "Page.Request" }), "webPartManager"); } PersonalizationScope initialScope = webPartManager.Personalization.InitialScope; IPrincipal user = null; if (requestInternal.IsAuthenticated) { user = page.User; } if (user == null) { initialScope = PersonalizationScope.Shared; } else { if (page.IsPostBack) { switch (page.Request["__WPPS"]) { case "s": initialScope = PersonalizationScope.Shared; break; case "u": initialScope = PersonalizationScope.User; break; } } else if ((page.PreviousPage != null) && !page.PreviousPage.IsCrossPagePostBack) { WebPartManager currentWebPartManager = WebPartManager.GetCurrentWebPartManager(page.PreviousPage); if (currentWebPartManager != null) { initialScope = currentWebPartManager.Personalization.Scope; } } else if (page.IsExportingWebPart) { initialScope = page.IsExportingWebPartShared ? PersonalizationScope.Shared : PersonalizationScope.User; } if ((initialScope == PersonalizationScope.Shared) && !webPartManager.Personalization.CanEnterSharedScope) { initialScope = PersonalizationScope.User; } } string hiddenFieldInitialValue = (initialScope == PersonalizationScope.Shared) ? "s" : "u"; page.ClientScript.RegisterHiddenField("__WPPS", hiddenFieldInitialValue); return(initialScope); }
/// <devdoc> /// </devdoc> public virtual PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } PersonalizationScope scope = webPartManager.Personalization.InitialScope; IPrincipal user = null; if (request.IsAuthenticated) { user = page.User; } if (user == null) { // if no user has been authenticated, then just load all user data scope = PersonalizationScope.Shared; } else { if (page.IsPostBack) { string postedMode = page.Request[scopeFieldName]; if (postedMode == sharedScopeFieldValue) { scope = PersonalizationScope.Shared; } else if (postedMode == userScopeFieldValue) { scope = PersonalizationScope.User; } } else if ((page.PreviousPage != null) && (page.PreviousPage.IsCrossPagePostBack == false)) { WebPartManager previousWebPartManager = WebPartManager.GetCurrentWebPartManager(page.PreviousPage); if (previousWebPartManager != null) { // Note that we check the types of the page, so we don't // look the at the PreviousPage in a cross-page posting scenario scope = previousWebPartManager.Personalization.Scope; } } // Special-case Web Part Export so it executes in the same security context as the page itself (VSWhidbey 426574) // Setting the initial scope from what's been asked for in the export parameters else if (page.IsExportingWebPart) { scope = (page.IsExportingWebPartShared ? PersonalizationScope.Shared : PersonalizationScope.User); } if ((scope == PersonalizationScope.Shared) && (webPartManager.Personalization.CanEnterSharedScope == false)) { scope = PersonalizationScope.User; } } string fieldValue = (scope == PersonalizationScope.Shared) ? sharedScopeFieldValue : userScopeFieldValue; page.ClientScript.RegisterHiddenField(scopeFieldName, fieldValue); return(scope); }