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