本文來自:https://blog.csdn.net/chengshiruxia/article/details/43526001
感謝原創的奉獻!
網站為utf-8編碼時IIS環境下運行出錯時iis給出的提示亂碼解決方法,本方法本人試個絕對可行,asp出錯時iis亂碼最終解決辦法,utf-8編碼網站出錯iis提示亂碼主要是因為IIS7的錯誤信息輸出默認使用的是GB2312編碼,這樣會導致IIS7出現運行時錯誤的信息會是亂碼,影響我們糾錯
在調試站點環境時,如果系統開發編碼使用的是UTF-8,iis錯誤提示亂碼解決方法。
1、將C:\inetpub\custerr\zh-CN\500-100.asp文件復制到你的站點文件夾下;
2、將這個文件另存為utf-8編碼:
a. 頭部加上 @codepage=65001; 如:<%@ language="VBScript" @codepage=65001 %>
b. option explicit后面加上一行response.charset="utf-8";
c. 將“<META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312">”修改為“<META HTTP-EQUIV="Content-Type" Content="text/html; charset=utf-8">”;
3. 配置IIS。
a. 打開IIS,選擇你建立的站點,在右邊窗口雙擊“錯誤頁”圖標,選擇右邊屬性窗口下的“添加...”操作。
b. 添加自定義錯誤頁窗口中,狀態代碼“500.100”。這里本來我想參照IIS6設置為500-100,結果系統提示不通過。響應操作,我們這里選擇“在此網站上執行URL”,URL地址“/siteName/500-100.asp”(siteName為你的虛擬站點名稱),如果建立的站點,這里只要輸入相對于站點根目錄的URL地址。
4. 確定后,這樣utf-8編碼站點顯示的出錯信息有會詳細的描述了不會是亂碼了。
示例:
-
<%@ language="VBScript" @codepage=65001 %>
-
<%
-
Option Explicit
-
response.charset="utf-8"
-
Const lngMaxFormBytes = 200
-
-
Dim objASPError, blnErrorWritten, strServername, strServerIP, strRemoteIP
-
Dim strMethod, lngPos, datNow, strQueryString, strURL
-
-
If Response.Buffer Then
-
Response.Clear
-
Response.Status = "500 Internal Server Error"
-
Response.ContentType = "text/html"
-
Response.Expires = 0
-
End If
-
-
Set objASPError = Server.GetLastError
-
%>
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-
<HTML><HEAD><TITLE>無法顯示該頁</TITLE>
-
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=utf-8">
-
<STYLE type="text/css">
-
BODY { font: 8pt/12pt verdana }
-
H1 { font: 13pt/15pt verdana }
-
H2 { font: 8pt/12pt verdana }
-
A:link { color: red }
-
A:visited { color: maroon }
-
</STYLE>
-
</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD>
-
-
<h1>無法顯示該頁</h1>
-
您嘗試訪問的頁面有問題,無法顯示。
-
<hr>
-
<p>請嘗試以下操作:</p>
-
<ul>
-
<li>與網站管理員聯系,告知對方此 URL 地址出現了此錯誤。</li>
-
</ul>
-
<h2>HTTP 500.100 - 內部服務器錯誤: ASP 錯誤。<br>Internet Information Services</h2>
-
<hr>
-
<p>技術信息(針對支持人員)</p>
-
<ul>
-
<li>錯誤類型:<br>
-
<%
-
Dim bakCodepage
-
on error resume next
-
bakCodepage = Session.Codepage
-
Session.Codepage = 1252
-
on error goto 0
-
Response.Write Server.HTMLEncode(objASPError.Category)
-
If objASPError.ASPCode > "" Then Response.Write Server.HTMLEncode(", " & objASPError.ASPCode)
-
Response.Write Server.HTMLEncode(" (0x" & Hex(objASPError.Number) & ")" ) & "<br>"
-
If objASPError.ASPDescription > "" Then
-
Response.Write Server.HTMLEncode(objASPError.ASPDescription) & "<br>"
-
elseIf (objASPError.Description > "") Then
-
Response.Write Server.HTMLEncode(objASPError.Description) & "<br>"
-
end if
-
blnErrorWritten = False
-
' Only show the Source if it is available and the request is from the same machine as IIS
-
If objASPError.Source > "" Then
-
strServername = LCase(Request.ServerVariables("SERVER_NAME"))
-
strServerIP = Request.ServerVariables("LOCAL_ADDR")
-
strRemoteIP = Request.ServerVariables("REMOTE_ADDR")
-
If (strServerIP = strRemoteIP) And objASPError.File <> "?" Then
-
Response.Write Server.HTMLEncode(objASPError.File)
-
If objASPError.Line > 0 Then Response.Write ", line " & objASPError.Line
-
If objASPError.Column > 0 Then Response.Write ", column " & objASPError.Column
-
Response.Write "<br>"
-
Response.Write "<font style=""COLOR:000000; FONT: 8pt/11pt courier new""><b>"
-
Response.Write Server.HTMLEncode(objASPError.Source) & "<br>"
-
If objASPError.Column > 0 Then Response.Write String((objASPError.Column - 1), "-") & "^<br>"
-
Response.Write "</b></font>"
-
blnErrorWritten = True
-
End If
-
End If
-
If Not blnErrorWritten And objASPError.File <> "?" Then
-
Response.Write "<b>" & Server.HTMLEncode( objASPError.File)
-
If objASPError.Line > 0 Then Response.Write Server.HTMLEncode(", line " & objASPError.Line)
-
If objASPError.Column > 0 Then Response.Write ", column " & objASPError.Column
-
Response.Write "</b><br>"
-
End If
-
%>
-
</li>
-
<li>瀏覽器類型:<br>
-
<%= Server.HTMLEncode(Request.ServerVariables("HTTP_USER_AGENT")) %>
-
<br><br></li>
-
<li>頁面:<br>
-
<%
-
strMethod = Request.ServerVariables("REQUEST_METHOD")
-
Response.Write strMethod & " "
-
If strMethod = "POST" Then
-
Response.Write Request.TotalBytes & " bytes to "
-
End If
-
Response.Write Request.ServerVariables("SCRIPT_NAME")
-
Response.Write "</li>"
-
If strMethod = "POST" Then
-
Response.Write "<p><li>POST Data:<br>"
-
' On Error in case Request.BinaryRead was executed in the page that triggered the error.
-
On Error Resume Next
-
If Request.TotalBytes > lngMaxFormBytes Then
-
Response.Write Server.HTMLEncode(Left(Request.Form, lngMaxFormBytes)) & " . . ."
-
Else
-
Response.Write Server.HTMLEncode(Request.Form)
-
End If
-
On Error Goto 0
-
Response.Write "</li>"
-
End If
-
%>
-
<br><br></li>
-
<li>時間:<br>
-
<%
-
datNow = Now()
-
Response.Write Server.HTMLEncode(FormatDateTime(datNow, 1) & ", " & FormatDateTime(datNow, 3))
-
on error resume next
-
Session.Codepage = bakCodepage
-
on error goto 0
-
%>
-
<br><br></li>
-
<li>詳細信息:<br>
-
<%
-
strQueryString = "prd=iis&sbp=&pver=5.0&ID=500;100&cat=" & Server.URLEncode(objASPError.Category) & "&os=&over=&hrd=&Opt1=" & Server.URLEncode(objASPError.ASPCode) & "&Opt2=" & Server.URLEncode(objASPError.Number) & "&Opt3=" & Server.URLEncode(objASPError.Description)
-
strURL = "http://www.microsoft.com/ContentRedirect.asp?" & strQueryString
-
%>
-
<ul>
-
<li>單擊 <a href="<%= strURL %>">Microsoft 支持</a>,可以找到有關此錯誤的文章鏈接。</li>
-
<li>轉到 <a href="http://go.microsoft.com/fwlink/?linkid=8180" target="_blank">Microsoft 產品支持服務</a>,執行標題搜索,查找詞語 <b>HTTP</b> 和 <b>500</b>。</li>
-
<li>打開 <b>IIS 幫助</b>(可從 IIS 管理器(inetmgr)訪問),搜索主題<b>網站管理</b>和<b>關于自定義錯誤消息</b>。</li>
-
<li>在 IIS 軟件開發包(SDK)中,或者在 <a href="http://go.microsoft.com/fwlink/?LinkId=8181">MSDN 聯機庫</a>中,搜索主題<b>調試 ASP 腳本</b>、<b>調試組件</b>和<b>調試 ISAPI 擴展功能和篩選器</b>。</li>
-
</ul>
-
</li>
-
</ul>
-
-
</TD></TR></TABLE></BODY></HTML>
html