angular - URL Rewrite 适用于我的所有 url,除了一个
问题描述
我的 ARR URL Rewrite 适用于所有简单的 url:s
/api/Login
,
/api/BusinessPartners
但不适合这个:
/api/sml.svc/LIF_cv_ServiceCallsParameters(FromDate='2019-11-04',ToDate='2019-11-11',CardCode='EMPTY',CallType=0,ProbType=0,ProbSubType=0,Status=0,Owner=0,Tech=0,LineStat='ASFC')/LIF_cv_ServiceCalls
我收到 404,找不到
我开发了一个托管在 Azure 应用服务中的 Angular 8 应用程序。后端位于其他地方并且没有启用 CORS,因此需要反向代理。我关注了 Ruslan 的部分内容http://ruslany.net/2014/05/using-azure-web-site-as-a-reverse-proxy/。另外,还有很多其他关于 ARR 反向代理的帖子。
这是我位于 /site 目录中的 applicationHost.xdt。
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false"
reverseRewriteHostInResponseHeaders="false">
</proxy>
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" xdt:Transform="InsertIfMissing" />
<add name="HTTP_ACCEPT_ENCODING" xdt:Transform="Insert" />
<add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="InsertIfMissing" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>
web.config 中的规则:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
<rule name="proxy" stopProcessing="true">
<match url="api/(.*)" />
<action type="Rewrite" url="http://XX.XX.XX.XX:50001/b1s/v1/{R:1}"/>
<serverVariables>
<!--set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" /-->
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
FailedRequestLog 的部分内容:
76. URL_CHANGED
OldUrl="/api/sml.svc/LIF_cv_ServiceCallsParameters(FromDate='2019-01-01',ToDate='2050-01-01',CardCode='EMPTY',CallType=0,ProbType=0,ProbSubType=0,Status=0,Owner=0,Tech=0,LineStat='U')/LIF_cv_ServiceCalls",
NewUrl="http://XX.XX.XX.XX:50001/b1s/v1/sml.svc/LIF_cv_ServiceCallsParameters(FromDate='2019-01-01',ToDate='2050-01-01',CardCode='EMPTY',CallType=0,ProbType=0,ProbSubType=0,Status=0,Owner=0,Tech=0,LineStat='U')/LIF_cv_ServiceCalls"
87. AspNetStart Data1="GET", Data2="/api/sml.svc", Data3=""
确切的调用NewUrl
在 PostMan 中起作用。
似乎重写规则以正确的方式处理了 url,但没有对后端进行调用(在远程机器中使用 wireshark 验证)。相反,AspNetStart 正在尝试读取文件或文件夹 api/sml.svc,最终导致 404 代码。
任何如何使它工作的建议都非常感谢!
解决方案
这终于解决了!
我为此问题调用了 Azure 支持。他们发现无法正常工作的原因是对似乎是 svc 服务的调用的身份验证失败。
添加 SVC 处理程序解决了该问题:
<system.webServer>
<handlers>
<remove name="svc-Integrated-4.0" />
<add name="svc-Integrated-4.0"
path="api/sml.svc/*."
verb="*"
type=" System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
作为记录:后端是 SAP Business One Servicel Layer。sml.svc 路径用于通过服务层公开的定制计算视图。
推荐阅读
- django - Django rest 框架 - 将图像上传到 Azure 存储
- java - @SessionAttributes 对于连续的获取请求不能正常工作
- fullcalendar - 如何将任何样式应用于 FullCalendar 单元格
- sass - 使用类属性嵌套 sass/scss 以
- python - Django Modelform - 它没有验证,为什么?
- vb.net - 在 winform 中运行 Async/Await 代码时,它会阻止 Winform UI,但在控制台模式下运行时可以工作
- r - 检查值列表是否在范围列表内(逐类)
- go - 打印结构数组只打印指针值
- python - Python 从委托账户发送电子邮件
- java - 按对象的属性对地图进行排序