SharePoint Enable session can use PowerShell, poke here; Webconfig can be modified.
The focus of this narrative is to control the session opening and closing sessions via feature.
Create a new empty SharePoint project, write the processing logic for the Featureeventhandler featureactivated and featuredeactivating
public override void FeatureActivated (Spfeaturereceiverproperties properties) {spwebapplication Applica tion = (spwebapplication) properties. Feature.parent; try {config.update (application); Application. Update (); Application. Farm.services.getvalue<spwebservice> (). Applywebconfigmodifications (); } catch {Config.restore (application); }} public override void FeatureDeactivating (Spfeaturereceiverproperties properties) {SPW Ebapplication application = (spwebapplication) properties. Feature.parent; try {config.restore (application); Application. Farm.services.getvalue<spwebservice> (). Applywebconfigmodifications (); } catch {}}
Here config is the processing class for the session, because enabling and disabling the session is essentially modifying the configuration of the IIS Web site, so get the WebApplication object and modify the Webconfig content through code.
The code for the Config class is as follows
Class Config {private static void Execupdate (Spwebapplication webApp, string name, string path, string value, M Icrosoft. SharePoint.Administration.SPWebConfigModification.SPWebConfigModificationType type) {spwebconfigmodific ation modification = new SPWebConfigModification (); modification. name = name; modification. Path = path; modification. Value = value; modification. Sequence = 0; modification. type = type; modification. Owner = "Sp_mip_team_enablesession"; SPWebConfigModification item = modification; WEBAPP.WEBCONFIGMODIFICATIONS.ADD (item); } public static void Restore (Spwebapplication webApp) {webapp.update (); list<spwebconfigmodification> configmodificationstoremove = new list<spwebconfigmodification> (); foreach (SPWebConfigModification spwebconfigmodification in webapp.webconfigmodifications){if (Spwebconfigmodification.owner = = "Sp_mip_team_enablesession") {con Figmodificationstoremove.add (spwebconfigmodification); }} foreach (SPWebConfigModification configmodification in Configmodificationstoremove) { WebApp.WebConfigModifications.Remove (configmodification); } webapp.update (); public static void Update (Spwebapplication webApp) {string name = NULL; string path = null; String value = null; Name = "add[@name = ' Session '] [@type = ' System.Web.SessionState.SessionStateModule ']"; Path = "/configuration/system.web/httpmodules"; Value = "<add name= ' Session ' type= ' System.Web.SessionState.SessionStateModule '/>"; Execupdate (webApp, name, path, value, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode); Name = "EnablesesSionstate "; Path = "/configuration/system.web/pages"; Value = "true"; Execupdate (webApp, name, path, value, SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute); Name = "add[@name = ' Session '] [@type = ' System.Web.SessionState.SessionStateModule, system.web, version=2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a '] "; Path = "/configuration/system.webserver/modules"; Value = "<add name= ' session ' type= ' System.Web.SessionState.SessionStateModule, system.web, version=2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a '/> "; Execupdate (webApp, name, path, value, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode); } }
The advantage of using the Spwebapplication object to record webconfigmodifications, or webconfig modifications, is that it is easy to restore the webconfig that were modified by the code.
SharePoint development-using session (Code modification Webconfig)