Monday, February 23, 2015

Programatically increase security validation timeout for a web application in Sharepoint

Environment: SharePoint Server 2013

Requirement: Programatically increase security validation timeout for a web application in SharePoint

Solution: The following line of code will set the Web Page Security Validation expiry to 60 minutes

   SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://webappURL/"));

   //Use TimeSpan constructor to specify Days, hours, minutes, seconds
    webApp.FormDigestSettings.Timeout = new TimeSpan(1, 0, 0); 

  //Save the changes 
    webApp.Update();

NoteYou'll get access denied error when the above code is executed within RWEP as it runs the code under the Application Pool account of the your web application. You need to run this code with farm account as the SPWebApplication is stored in config database. Use SPUserToken and farm account to run this code.

No comments:

Post a Comment