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
//Use TimeSpan constructor to specify Days, hours, minutes, seconds
webApp.FormDigestSettings.Timeout = new TimeSpan(1, 0, 0);
//Save the changes
webApp.Update();
Note: You'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.
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();
Note: You'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