0
我有一個網站和api配置在我的主機上偵聽80和443.我試圖拆分2並將它們放在不同的端口上,並使用IIS URL重寫來路由請求。Url重寫和自定義錯誤消息
所以,我創建了一個新的空白網站只有一個web.config,把我的重寫規則在那裏,我的請求被正確路由,但是我不能夠得到工作的情況下,API返回400
也就是說,如果你直接ping操作錯誤請求的API(指定端口),它正確地返回400錯誤的請求JSON響應
400 Bad Request
Pragma: no-cache
X-CorrelationId: 823fc2fd-4ed2-46b6-86e0-50b2abf5d61b
X-Content-Type-Options: nosniff
Request-Processing-Time: 606.4377 ms
OData-Version: 4.0
Content-Length: 142
Cache-Control: no-cache
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
Date: Wed, 14 Oct 2015 21:39:58 GMT
Expires: -1
P3P: CP="CAO DSP COR ADMa DEV CONi TELi CUR PSA PSD TAI IVDi OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR"
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
{
"error":{
"code":"20112","message":"Invalid Entity ID specified.",
}
}
但是通過URL重寫你看到一個HTML頁面
400 Bad Request
Content-Length: 3506
Cache-Control: private
Content-Type: text/html; charset=utf-8
Date: Wed, 14 Oct 2015 21:33:42 GMT
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
<!DOCTYPE html>
<html>
<head>
<title>A potentially dangerous Request.Path value was detected from the client (:).</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
我曾嘗試將<httpErrors existingResponse="PassThrough"/>
添加到web.config中,但這並沒有幫助...
編輯:我有一個主角,它似乎與無效字符有關,api有一個參數: 。仍試圖找出如何解決該問題
編輯2:請參閱下面答案中的解決方案。
有關如何解決此問題的任何提示?
你的請求是怎麼樣的? – jgasiorowski