Thursday 29 January 2015

Troubleshooting SharePoint HTTP 500 Errors


One of colleague faced http 500 error whenever he was trying to access any SharePoint Site.
He also tried to open from IIS but no luck.  He actually updated the Server 2012 to Server 2012 R2.
He discussed this issue with me.

I then started looking logs and all the stuffs (done surfing also) and found that the issue was with Security Token Service. Though it was not stopped but throwing following error:

The requested service, 'http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc' could not be activated. See the server's diagnostic trace logs for more information.

I then find two solution from this link. 1st one didn't work for me but 2nd one.

By using following PowerShell CmdLet, I was able to fix STS issue and also SharePoint sites started working properly

Add-PSSnapin microsoft.sharepoint.powershell
$hostConfig = Get-SPServiceHostconfig

$hostConfig.Provision()

$SPservices = Get-SPServiceApplication

foreach ($SPservice in $SPservices ) 

   $SPservice .provision();
   write-host $SPservice.name
}

Please don't miss IIS reset 

Updated cmdLet:

After getting feedback and comments from Brain, I decided to review the cmdLet and make it more convincing and I am able to do this. Now no need to provision all the services but only STS and here is the cmdLet for the same:

Add-PSSnapin microsoft.sharepoint.powershell
$hostConfig = Get-SPServiceHostconfig
$hostConfig.Provision()
$SPservice = Get-SPServiceApplication |?{$_.name -eq 'SecurityTokenServiceApplication'}
$SPservice.Provision();

Import-Module WebAdministration
Stop-Website 'SharePoint Web Services'

Start-Website 'SharePoint Web Services'

Hope this will make sense

5 comments :

  1. This is actually a generic error that may have multiple root causes. Being said, I'd be hesitant in running this PowerShell, which would implement the provision method for all of the service applications in the farm (and each service application may implement this differently... for example, the implementation for the search service application is different than the user profile service application.

    Also, for what it's worth, service endpoints (like the problematic one in your example) tend to be related to service instances (as in Get-SPServiceInstance) on a particular server in the farm instead of a service application (as in Get-SPServiceApplication like your example) which has no server affinity.

    Being said, the iisreset is what likely fixed your transient failure in that endpoint...

    ReplyDelete
    Replies
    1. Thanks Brian for your concern and comment.
      Actually, I have tried many solutions but worked the above one only.

      Also I have posted the issue faced by colleague. He just upgraded the OS and then the issue started coming.
      Actually, Security Token Service is WCF service and some how its endpoint gets broken.
      In my view, If you are provisioning this then you need to refresh the service application again.

      Please share your thought over this

      Delete
    2. Fair enough and understood if you determine that specific service application needs to be re-provisioned... but the PowerShell example is suggesting to re-provision ALL of the service applications, which is probably way too broad in most cases. In other words, the sample code suggests provisioning each service application in the farm - not just the Security Token Service application.

      For example, run this to list out how much you're really impacting:
      $serviceApplications = Get-SPServiceApplication
      foreach ($app in $serviceApplications) { $app.Name }

      Delete
  2. Thanks Brain.

    I will try to test only with Security Token Service application and update my code :)

    Thanks for your feedback.

    ReplyDelete
  3. Thanks Ajeet,
    A really nice article. I was facing this issue and none of my web application were working and through this article my issue was resolved...
    Thanks a bunch.....:):):)...

    ReplyDelete