本文来自: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