URL重写和自定义错误消息 [英] Url rewrite and custom error message

查看:165
本文介绍了URL重写和自定义错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的主机监听80和443我试图分裂2和把它们放在单独的端口和使用IIS URL重写将请求路由上配置一个网站和一个API。

I have a website and a api configured on my host listening on 80 and 443. I am trying to split the 2 and put them on separate ports and use IIS url rewrite to route requests.

所以,我创建了一个新的空白网站只有一个web.config,把我的重写规则在那里,我的请求被正确路由​​,但是我没能得到工作,其中API返回400的情况。

So, I created a new blank site with just a web.config and put my rewrite rules there, my requests are being routed correctly, however I am not able to get the case working where the API returns 400.

即。如果您ping直接坏请求(指定端口)的API,它正确返回400错误请求JSON响应

i.e. if you ping the API with a Bad request directly (specify the port), it correctly returns a 400 Bad request json response

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页面

However through URL rewrite you see a html page

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;}

我曾尝试加入&LT; httpErrors existingResponse =直通/&GT; 来的web.config中,但没有帮助...

I have tried adding <httpErrors existingResponse="PassThrough"/> to the web.config but that didn't help...

编辑:我有一引,似乎无效字符是相关的API有一个参数:在里面。仍在试图弄清楚如何处理那些

I have a lead, it seems to be related to invalid chars, the api has a param with : in it. Still trying to figure out how to tackle that

编辑2:参见下面的答案分辨率

Edit 2: See resolution in the answer below.

这是如何解决这个任何提示?

Any tips on how to resolve this?

推荐答案

那么,问题是,API允许在URL中一些特殊字符,我曾在web.config中指定

So, the problem was that the api allows some special characters in the url, which I had to specify in the web.config

请参阅链接: http://forums.iis.net/t/1193674.aspx

我最终加入以下行到web.config中:

I ended up adding the following line to the web.config:

<httpRuntime targetFramework="4.5" requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\"/>

这篇关于URL重写和自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆