Пример #1
0
        protected virtual PersonalizationScope Load()
        {
            if (!this.Enabled)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("WebPartPersonalization_PersonalizationNotEnabled"));
            }
            this.DeterminePersonalizationProvider();
            Page page = this.WebPartManager.Page;

            if (page == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "WebPartManager.Page" }));
            }
            HttpRequest requestInternal = page.RequestInternal;

            if (requestInternal == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "WebPartManager.Page.Request" }));
            }
            if (requestInternal.IsAuthenticated)
            {
                this._userCapabilities = this._provider.DetermineUserCapabilities(this.WebPartManager);
            }
            this._personalizationState = this._provider.LoadPersonalizationState(this.WebPartManager, false);
            if (this._personalizationState == null)
            {
                throw new ProviderException(System.Web.SR.GetString("WebPartPersonalization_CannotLoadPersonalization"));
            }
            return(this._provider.DetermineInitialScope(this.WebPartManager, this._personalizationState));
        }
        public override void SavePersonalizationState(PersonalizationState state)
        {
            //  Take care of the unexpected personalization behavior, when User scope is not used, we need to ensure that scope is able to be changed to shared scope.
            //  1. check web.config authorization section that enterSharedScope is allowed to * users. 
            //  2. misconfigured authorization section leads to data loss due to the personalization data becomes user scope before saving the state

			if (state.WebPartManager.Personalization.Scope == PersonalizationScope.User)
            {
                try
                {
                    SenseNetPersonalizationProvider.WriteLog(string.Format("SavePersonalizationState --> Personalization.Scope = PersonalizationScope.User: trying to ToggleScope();"));
                    state.WebPartManager.Personalization.ToggleScope();
                }
                catch (InvalidOperationException exc) //logged
                {
                    Logger.WriteException(exc);
                }
                catch (ArgumentOutOfRangeException exc) //logged
                {
                    Logger.WriteException(exc);
                }
            }


            try
            {
                base.SavePersonalizationState(state);
            }
            catch (InvalidContentActionException ex)
            {
                //not enough permissions to save page state, never mind
                Logger.WriteException(ex);
            }
            
        }
Пример #3
0
        public virtual void SavePersonalizationState(PersonalizationState state)
        {
            string str;
            string str2;

            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            BlobPersonalizationState state2 = state as BlobPersonalizationState;

            if (state2 == null)
            {
                throw new ArgumentException(System.Web.SR.GetString("PersonalizationProvider_WrongType"), "state");
            }
            WebPartManager webPartManager = state2.WebPartManager;

            this.GetParameters(webPartManager, out str, out str2);
            byte[] dataBlob = null;
            bool   isEmpty  = state2.IsEmpty;

            if (!isEmpty)
            {
                dataBlob = state2.SaveDataBlob();
                isEmpty  = (dataBlob == null) || (dataBlob.Length == 0);
            }
            if (isEmpty)
            {
                this.ResetPersonalizationBlob(webPartManager, str, str2);
            }
            else
            {
                this.SavePersonalizationBlob(webPartManager, str, str2, dataBlob);
            }
        }
Пример #4
0
        /// <devdoc>
        /// Loads personalization information from its storage, and computes the initial personalization
        /// scope. This method determines the provider type to be used, and the current user's capabilities.
        /// </devdoc>
        protected virtual PersonalizationScope Load()
        {
            if (!Enabled)
            {
                throw new InvalidOperationException(SR.GetString(SR.WebPartPersonalization_PersonalizationNotEnabled));
            }

            // Determine the provider early, as it is needed to continue execution.
            // Provider is used to detect user's capabilities, load personalization state
            // and determine initial scope.
            DeterminePersonalizationProvider();
            Debug.Assert(_provider != null);

            Page page = WebPartManager.Page;

            if (page == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.PropertyCannotBeNull, "WebPartManager.Page"));
            }

            HttpRequest request = page.RequestInternal;

            if (request == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.PropertyCannotBeNull, "WebPartManager.Page.Request"));
            }

            // Ask the provider to load information about what are the capabilities of
            // the current user
            if (request.IsAuthenticated)
            {
                _userCapabilities = _provider.DetermineUserCapabilities(WebPartManager);
            }

            // A derived WebPartPersonalization can have ignoreCurrentUser to be true.
            _personalizationState = _provider.LoadPersonalizationState(WebPartManager, /* ignoreCurrentUser */ false);
            if (_personalizationState == null)
            {
                // We can't assume that _personalizationState will be non-null, because
                // it depends on the provider implementation.
                throw new ProviderException(SR.GetString(SR.WebPartPersonalization_CannotLoadPersonalization));
            }

            return(_provider.DetermineInitialScope(WebPartManager, _personalizationState));
        }
Пример #5
0
        /// <devdoc>
        /// Allows the provider to save personalization data. The specified information
        /// contains a reference to the WebPartManager, which is used to access the
        /// current Page, and its path and user information.
        /// </devdoc>
        public virtual void SavePersonalizationState(PersonalizationState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            BlobPersonalizationState blobState = state as BlobPersonalizationState;

            if (blobState == null)
            {
                throw new ArgumentException(SR.GetString(SR.PersonalizationProvider_WrongType), "state");
            }

            WebPartManager webPartManager = blobState.WebPartManager;

            string path;
            string userName;

            GetParameters(webPartManager, out path, out userName);

            byte[] dataBlob = null;
            bool   reset    = blobState.IsEmpty;

            if (reset == false)
            {
                dataBlob = blobState.SaveDataBlob();
                reset    = (dataBlob == null) || (dataBlob.Length == 0);
            }

            if (reset)
            {
                ResetPersonalizationBlob(webPartManager, path, userName);
            }
            else
            {
                SavePersonalizationBlob(webPartManager, path, userName, dataBlob);
            }
        }
 public virtual new void SavePersonalizationState(PersonalizationState state)
 {
 }
Пример #7
0
        public override void SavePersonalizationState(PersonalizationState state)
        {
            if (this.IsEnabled)
            {
                DictionaryPersonalizationState dictionaryState = state as DictionaryPersonalizationState;
                if (null == dictionaryState)
                    throw new ArgumentException("state is not a DictionaryPersonalizationState");

                if (!dictionaryState.ReadOnly)
                {
                    StringBuilder personalizationBuilder = new StringBuilder();
                    using (StringWriter stringWriter = new StringWriter(personalizationBuilder))
                    {
                        using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                        {
                            writer.Formatting = Formatting.Indented;
                            writer.WriteStartDocument();
                            writer.WriteStartElement("personalization");
                            writer.WriteAttributeString("version", ReflectionServices.Version());
                            foreach (string id in dictionaryState.States.Keys)
                            {
                                if (dictionaryState.IsPartPresent(id))
                                {
                                    writer.WriteStartElement("part");
                                    writer.WriteAttributeString("id", id);
                                    foreach (string propertyName in dictionaryState.States[id].Keys)
                                    {
                                        writer.WriteStartElement("property");
                                        writer.WriteAttributeString("name", propertyName);
                                        writer.WriteStartAttribute("sensitive");
                                        writer.WriteValue(dictionaryState.States[id][propertyName].IsSensitive);
                                        writer.WriteEndAttribute();
                                        writer.WriteStartAttribute("scope");
                                        writer.WriteValue((int)dictionaryState.States[id][propertyName].Scope);
                                        writer.WriteEndAttribute();
                                        object value = dictionaryState.States[id][propertyName].Value;
                                        if (null != value)
                                        {
                                            writer.WriteStartElement("value");
                                            writer.WriteStartAttribute("type");
                                            writer.WriteValue(SerializationServices.ShortAssemblyQualifiedName(value.GetType().AssemblyQualifiedName));
                                            writer.WriteEndAttribute();
                                            SerializationServices.Serialize(value, writer);
                                            writer.WriteEndElement();
                                        }
                                        writer.WriteEndElement();
                                    }
                                    writer.WriteEndElement();
                                }
                            }
                            writer.WriteEndElement();
                            writer.WriteEndDocument();
                        }
                    }
                    PersonalizationStorage.Instance.Write(XmlPersonalizationProvider.StorageKey, personalizationBuilder.ToString());
                }
            }
        }
Пример #8
0
        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);
        }
 public virtual new PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState)
 {
     return(default(PersonalizationScope));
 }
        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;
        }
 public virtual new PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState)
 {
   return default(PersonalizationScope);
 }
Пример #12
0
        /// <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);
        }
 public virtual void SavePersonalizationState(PersonalizationState state)
 {
     string str;
     string str2;
     if (state == null)
     {
         throw new ArgumentNullException("state");
     }
     BlobPersonalizationState state2 = state as BlobPersonalizationState;
     if (state2 == null)
     {
         throw new ArgumentException(System.Web.SR.GetString("PersonalizationProvider_WrongType"), "state");
     }
     WebPartManager webPartManager = state2.WebPartManager;
     this.GetParameters(webPartManager, out str, out str2);
     byte[] dataBlob = null;
     bool isEmpty = state2.IsEmpty;
     if (!isEmpty)
     {
         dataBlob = state2.SaveDataBlob();
         isEmpty = (dataBlob == null) || (dataBlob.Length == 0);
     }
     if (isEmpty)
     {
         this.ResetPersonalizationBlob(webPartManager, str, str2);
     }
     else
     {
         this.SavePersonalizationBlob(webPartManager, str, str2, dataBlob);
     }
 }
 public override void SavePersonalizationState(PersonalizationState state)
 {
     base.SavePersonalizationState(state);
 }
 protected virtual PersonalizationScope Load()
 {
     if (!this.Enabled)
     {
         throw new InvalidOperationException(System.Web.SR.GetString("WebPartPersonalization_PersonalizationNotEnabled"));
     }
     this.DeterminePersonalizationProvider();
     Page page = this.WebPartManager.Page;
     if (page == null)
     {
         throw new InvalidOperationException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "WebPartManager.Page" }));
     }
     HttpRequest requestInternal = page.RequestInternal;
     if (requestInternal == null)
     {
         throw new InvalidOperationException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "WebPartManager.Page.Request" }));
     }
     if (requestInternal.IsAuthenticated)
     {
         this._userCapabilities = this._provider.DetermineUserCapabilities(this.WebPartManager);
     }
     this._personalizationState = this._provider.LoadPersonalizationState(this.WebPartManager, false);
     if (this._personalizationState == null)
     {
         throw new ProviderException(System.Web.SR.GetString("WebPartPersonalization_CannotLoadPersonalization"));
     }
     return this._provider.DetermineInitialScope(this.WebPartManager, this._personalizationState);
 }
        /// <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;
        }
        /// <devdoc>
        /// Allows the provider to save personalization data. The specified information
        /// contains a reference to the WebPartManager, which is used to access the
        /// current Page, and its path and user information.
        /// </devdoc>
        public virtual void SavePersonalizationState(PersonalizationState state) {
            if (state == null) {
                throw new ArgumentNullException("state");
            }

            BlobPersonalizationState blobState = state as BlobPersonalizationState;
            if (blobState == null) {
                throw new ArgumentException(SR.GetString(SR.PersonalizationProvider_WrongType), "state");
            }

            WebPartManager webPartManager = blobState.WebPartManager;

            string path;
            string userName;
            GetParameters(webPartManager, out path, out userName);

            byte[] dataBlob = null;
            bool reset = blobState.IsEmpty;

            if (reset == false) {
                dataBlob = blobState.SaveDataBlob();
                reset = (dataBlob == null) || (dataBlob.Length == 0);
            }

            if (reset) {
                ResetPersonalizationBlob(webPartManager, path, userName);
            }
            else {
                SavePersonalizationBlob(webPartManager, path, userName, dataBlob);
            }
        }
 public virtual new void SavePersonalizationState(PersonalizationState state)
 {
 }
 public override PersonalizationScope DetermineInitialScope(
     WebPartManager webPartManager, 
     PersonalizationState loadedState)
 {
     return base.DetermineInitialScope(webPartManager, loadedState);
 }
        /// <devdoc>
        /// Loads personalization information from its storage, and computes the initial personalization
        /// scope. This method determines the provider type to be used, and the current user's capabilities.
        /// </devdoc>
        protected virtual PersonalizationScope Load() {
            if (!Enabled) {
                throw new InvalidOperationException(SR.GetString(SR.WebPartPersonalization_PersonalizationNotEnabled));
            }

            // Determine the provider early, as it is needed to continue execution.
            // Provider is used to detect user's capabilities, load personalization state
            // and determine initial scope.
            DeterminePersonalizationProvider();
            Debug.Assert(_provider != null);

            Page page = WebPartManager.Page;
            if (page == null) {
                throw new InvalidOperationException(SR.GetString(SR.PropertyCannotBeNull, "WebPartManager.Page"));
            }

            HttpRequest request = page.RequestInternal;
            if (request == null) {
                throw new InvalidOperationException(SR.GetString(SR.PropertyCannotBeNull, "WebPartManager.Page.Request"));
            }

            // Ask the provider to load information about what are the capabilities of
            // the current user
            if (request.IsAuthenticated) {
                _userCapabilities = _provider.DetermineUserCapabilities(WebPartManager);
            }

            // A derived WebPartPersonalization can have ignoreCurrentUser to be true.
            _personalizationState = _provider.LoadPersonalizationState(WebPartManager, /* ignoreCurrentUser */ false);
            if (_personalizationState == null) {
                // We can't assume that _personalizationState will be non-null, because
                // it depends on the provider implementation.
                throw new ProviderException(SR.GetString(SR.WebPartPersonalization_CannotLoadPersonalization));
            }

            return _provider.DetermineInitialScope(WebPartManager, _personalizationState);
        }