PowerShell kullanarak Web.Config'i düzenleyerek Özel Hatayı Etkinleştirme/Devre Dışı Bırakma


SharePoint'teki gerçek hataları ortaya çıkarmak için, SharePoint sanal dizininin kökünde bulunan web.config dosyasını düzenleyerek özel hata sayfasını kapatıyorduk.

  • Web.config'i Not Defteri'nde açın
  • “CallStack”ı arayın, “false” yerine “true” olarak değiştirin
  • “CustomErrors mode”u arayın, değerini “On” yerine “Off” olarak değiştirin
  • Kaydet ve kapat.
Uyarı: Web.config dosyası oldukça hassastır! küçük bir yazım hatası bile SharePoint sitenizin çökmesine neden olabilir!

Tipik SharePoint 2007 "Bilinmeyen Hata"

ve SharePoint 2010'un "Beklenmeyen bir hata oluştu"


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function ConfigureCustomError()
{
  Param( [Parameter(Mandatory=$true)] [string]$WebAppURL,  [parameter(Mandatory=$true)] $Option )

 #Get the web application
 $WebApp = Get-SPWebApplication $WebAppURL
 #Get the Web Application Zone
 $Zone = $WebApp.AlternateUrls[0].UrlZone
 # Get the IIS settings for the zone
 $IISSettings = $WebApp.IISSettings[$zone]
 # Get the path from the settings
 $WebConfigPath = $IISSettings.Path.ToString() + "\web.config"

 #Backup web.config file
 $now = [datetime]::now.ToString('dd-MM-yyyy hh-mm-ss')
 $BackupFile =$IISSettings.Path.ToString()+ "\web.config.$now"
 copy-item $WebConfigPath -destination $BackupFile

 #Get the Web.config File
 $XMLDoc = new-object System.Xml.XmlDocument
 $XMLDoc.Load($WebConfigPath)
  switch($option)
  {
  "OFF" { 
    #Apply Change
    $XMLDoc.get_DocumentElement()."sharepoint".safemode.callstack = "True"
    $XMLDoc.get_DocumentElement()."system.web".customErrors.mode = "Off"
    Write-Host "Custom Error Mode has been Disabled, Now you can get the actual errors!"
    }
  "ON" {
    $XMLDoc.get_DocumentElement()."sharepoint".safemode.callstack = "False"
    $XMLDoc.get_DocumentElement()."system.web".customErrors.mode = "ON"
    Write-Host "Custom Error Mode has been Enabled, SharePoint displays default custom error Page!"
    }
  }
 $XMLDoc.Save($WebConfigPath)
 }

#Call the function to Turn OFF custom errors
ConfigureCustomError "https://sharepoint.crescent.com" "OFF"

İlgili makaleler