简体   繁体   English

IIS URL重写和ARR无法正确处理重写规则

[英]IIS URL Rewrite and ARR don't handle rewrite rule properly

I have a problem with some understanding of how the URL Rewrite and ARR work together. 我对URL重写和ARR如何协同工作有所了解。 I have a site and a standalone service that generates and provides updated sitemaps for the site. 我有一个网站和一个独立服务,该服务会生成并提供该网站的更新站点地图。 Below is my rule to handle sitemap requests. 以下是我处理站点地图请求的规则。 It is a local rule in the web.config under sites directory (the site is hosted under IIS 10). 这是web.config站点目录下的本地规则(站点托管在IIS 10下)。

<rule name="Sitemap Rule" stopProcessing="true">
      <match url="^sitemap.*" />
      <action type="Rewrite" url="http://sitemap.mysitedomain/provider?key={R:0}" logRewrittenUrl="true" />
</rule>

All looks good but it doesn't work. 一切看起来不错,但是不起作用。 The only response I've got is 404. I should note that the ARR module is active and it properly handles other proxy requests. 我唯一的响应是404。我应该注意,ARR模块处于活动状态,并且可以正确处理其他代理请求。

To be transparent on this rule imagine that some web-robot request http://mysitedomain/sitemap.xml and the real request will be served from the http://sitemap.mysitedomain/provider?key=sitemap.xml where sitemap.mysitedomain is hosted on different servers and different environment. 为了透明起见 ,假设某些网络机器人请求http://mysitedomain/sitemap.xml和实际请求将从http://sitemap.mysitedomain/provider?key = sitemap.xml提供 ,其中sitemap.mysitedomain托管在不同的服务器和不同的环境上。

The strange things here is that if I put empty sitemap.xml to the root of mysitedomain all my requests to the sitemap.xml start working as expected and I started to get updated sitemap.xml from sitemap service and an empty one that I've placed to the root of the site. 奇怪的是,如果我将空的sitemap.xml放在mysitedomain的根目录中,则所有对sitemap.xml的请求都将按预期开始工作,并且我开始从sitemap服务中获取更新的sitemap.xml和一个空的放置到网站的根目录。


Added some tracing info from failed request 从失败的请求中添加了一些跟踪信息

For the failed requests I have next in the tracing file 对于失败的请求,我接下来在跟踪文件中

...
ModuleName    RewriteModule

HeaderName    X-Original-URL 
HeaderValue   /sitemap.xml 
Replace       true 

OldUrl       /sitemap.xml 
NewUrl       http://sitemap.mysitedomain/v1/sitemap/provider?key=sitemap.xml

...

ModuleName            ApplicationRequestRouting 
Notification          MAP_REQUEST_HANDLER 
fIsPostNotification   false 
...
OldUrl                http://sitemap.laf24.ru/v1/sitemap/provider?key=sitemap.xml 
NewUrl                /sitemap.xml 

...

ModuleName            ManagedPipelineHandler 
Notification          EXECUTE_REQUEST_HANDLER 
HttpStatus            404 
HttpReason            Not Found 
HttpSubStatus         0 
ErrorCode             The operation completed successfully. (0x0) 

I should point again that if I place an empty sitemap.xml to the root of mysitedomain, than all start working as expected. 我应该再次指出,如果我将一个空的sitemap.xml放置到mysitedomain的根目录,则所有内容都将按预期开始工作。 I got actual data from sitemap.mysitedomain. 我从sitemap.mysitedomain获得了实际数据。

I have found why it is happen and it is not a problem with Url Rewrite or ARR modules. 我发现了为什么会发生这种情况,而Url Rewrite或ARR模块不是问题。 The main reason is that ASP.Net handle such requests and return 404 because there are no routes defined to process such paths. 主要原因是ASP.Net处理此类请求并返回404,因为没有定义用于处理此类路径的路由。

To fix this we added ignore definitions for sitemaps urls 为了解决这个问题,我们为Sitemaps网址添加了忽略定义

routes.IgnoreRoute("sitemap.xml");
routes.IgnoreRoute("sitemap/{*pathInfo}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM