برای ظاهر کردن خطاهای فعلی در شیرپوینت ، ما باید با ویرایش پرونده web.config، صفحه خطای سفارشی را خاموش کنیم.
![1](/images/education_image/enable-disable-custom-error-by-editing-web-config-using-powershell/1.png)
web.config را در Notepad باز کنید.
کلمه "CallStack" را سرچ کنید، آن را از "false" به "true" تغییر دهید.
کلمه " CustomeError mode" را سرچ کنید ، مقدار آن را از "on" به "off" تغییر دهید.
ذخیره کنید و Notepad را ببندید.
در زیر نوعی خطا در شیرپوینت 2007 و شیرپوینت 2010 مشاهده می کنید.
![2](/images/education_image/enable-disable-custom-error-by-editing-web-config-using-powershell/2.png)
![3](/images/education_image/enable-disable-custom-error-by-editing-web-config-using-powershell/3.png)
در ادامه اسکریپت PowerShell برای فعال یا غیرفعال کردن صفحه خطای سفارشی شیرپوینت را مشاهده خواهید کرد:
Add-PSSnapinMicrosoft.SharePoint.PowerShell -ErrorActionSilentlyContinue
Function ConfigureCustomError()
{
Param( [Parameter(Mandatory=$true)] [string]$WebAppURL, [parameter(Mandatory=$true)] $Option)
<#
.Description
This PowerShell function Enables / Disables SharePoint Custom Error by editing web.config file
.Example
ConfigureCustomError "http://sharepoint.crescent.com""OFF"
This disables SharePoint's default custom error page and reveals actual error
.Link
http://www.sharepointdiary.com
http://twitter.com/SharePointdiary
.Inputs
$WebAppURL- Web Application URL in which the Custom Errors to be set
$Option- ON or OFF
.Outputs
Sets "CustomErrors mode"and "CallStack"values in web.config file
#>
#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-objectSystem.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 "http://sharepoint.crescent.com""OFF"
فعال و غیرفعال کردن خطاهای سفارشی با استفاده از ویرایش Web.Config در PowerShell