Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Response.Charset'
在 NetBox、某些精簡版 IIS 或 特定 ASP 執行環境 中,Response.Charset 屬性不存在。
' 原本寫法(會報錯)
' Response.CharSet = "GB2312"
' 替代寫法:直接設定完整 Content-Type 標頭
Response.AddHeader "Content-Type", "text/html; charset=gb2312"
Response.Charset 是 IIS ASP 的便利屬性,底層實際做的就是設定 Content-Type 標頭的 charset 參數。Response.AddHeader 是標準 HTTP 標頭操作方法,所有 ASP 相容環境皆支援。Response.AddHeader "Content-Type", "媒體類型; charset=編碼"| 編碼 | Content-Type 範例 |
|---|---|
| UTF-8(推薦) | text/html; charset=utf-8 |
| Big5(繁體中文) | text/html; charset=big5 |
| GB2312(簡體中文) | text/html; charset=gb2312 |
| JSON API | application/json; charset=utf-8 |
| XML | application/xml; charset=utf-8 |
<%
Response.Buffer = True
Response.AddHeader "Content-Type", "text/html; charset=utf-8"
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ASP 編碼設定範例</title>
</head>
<body>
<h1>中文顯示正常:測試 12345</h1>
</body>
</html>
<%
Response.AddHeader "Content-Type", "application/json; charset=utf-8"
Response.Write "{""status"":""ok"",""msg"":""中文訊息正常""}"
%>
<head> 第一行放置 <meta charset="utf-8">,瀏覽器優先參考。...;CharSet=utf-8(SQL Server)或確保 Access 資料庫為 Unicode 格式。Response.Charset,改用 AddHeader 相容性最佳。