简体   繁体   English

IIS URL 重写不起作用,输入 URL 甚至没有被捕获?

[英]IIS URL rewrite not working, the input URL not even captured?

The Failed Request Tracing works fine to log failed rewritings.失败的请求跟踪可以很好地记录失败的重写。 I can view the log files and at least understand why the rewriting not working.我可以查看日志文件,至少可以理解为什么重写不起作用。

The regex pattern has passed a matching test OK, but the input URLs I enter in the browser are not even captured.正则表达式模式已通过匹配测试 OK,但我在浏览器中输入的输入 URL 甚至没有被捕获。 All the URLs mapped to controller actions are captured (my website is an ASP.NET MVC app) however the URL I need to be rewritten is not mapped to any, the page shows 404. But I expect it to be rewritten to some working URL (to test it out, so that instead of showing 404, it should be rewritten to the target url and shows the returned content from there). All the URLs mapped to controller actions are captured (my website is an ASP.NET MVC app) however the URL I need to be rewritten is not mapped to any, the page shows 404. But I expect it to be rewritten to some working URL (to对其进行测试,以便将其重写为目标 url 并显示从那里返回的内容,而不是显示 404)。

My URL rewriting rule uses a Reverse Proxy template.我的 URL 重写规则使用Reverse Proxy模板。

I hope what I understand here is correct.我希望我在这里的理解是正确的。 How can I diagnose this?我该如何诊断? My purpose is just to do something like turning IIS into a reverse proxy by capturing all requests through my website, check if any matching the defined regex pattern before requesting to the rewritten URL and returning back the content to the original client.我的目的只是通过捕获通过我的网站的所有请求来将 IIS 转换为反向代理,在请求重写的 URL 并将内容返回给原始客户端之前检查是否有任何匹配定义的正则表达式模式。

Update更新

For those who may not know about ASP.NET MVC:对于那些可能不了解 ASP.NET MVC 的人:

Suppose my website has a controller called HomeController with action Index and the URL mapped to it is /Home/Index .假设我的网站有一个名为HomeController的 controller 带有操作Index ,并且映射到它的 URL 是/Home/Index

The URL I mean not mapped to any action here may be /Home/TestProxy Here the HomeController does not expose any action TestProxy and also there is not any routing rule maps /Home/TestProxy to any action. URL 我的意思是这里没有映射到任何动作可能是/Home/TestProxy这里HomeController没有公开任何动作TestProxy也没有任何路由规则映射/Home/TestProxy到任何动作。 So in this case the ASP.NET MVC app will shows a 404 page.因此,在这种情况下,ASP.NET MVC 应用程序将显示404页面。

As I said above, for the URLs mapped to a valid controller action, they seem to be captured and considered as input URLs (before being checked against the rewriting rule).如上所述,对于映射到有效 controller 操作的 URL,它们似乎被捕获并视为输入 URL (在根据重写规则检查之前)。 But for URLs not mapped to any controller action (showing 404), I don't see any logged as input URLs (so of course they will not be checked against the rewriting rule and it won't work).但是对于未映射到任何 controller 操作(显示 404)的 URL,我看不到任何记录为输入 URL(因此,它们当然不会根据重写规则进行检查,也不会起作用)。

Update 2更新 2

Actually my tested URL is not even mapped to a controller so looks like it's not logged by the Failed Requests Tracing rule I setup.实际上,我测试的 URL 甚至没有映射到 controller 所以看起来它没有被我设置的失败请求跟踪规则记录。 Now I've tried using a URL mapped to a controller but not to any action (it still shows 404) but successfully logged by the Failed Request Tracing rule.现在我尝试使用映射到 controller 的 URL 但没有任何操作(它仍然显示 404),但成功地被“失败的请求跟踪”规则记录。 I can see this in the log file:我可以在日志文件中看到这一点:

<EventData>
   <Data Name="ContextId">{80000034-0000-F000-B63F-84710C7967BB}</Data>
   <Data Name="Pattern">testproxy/(.*)</Data>
   <Data Name="Input">home/testproxy/index</Data>
   <Data Name="Negate">false</Data>
   <Data Name="Matched">true</Data>
</EventData>

So it reported a matched pattern, but still the page shows 404, whereas I expected it to return the content from the rewritten url (which should be http://10.0.0.5/index - I confirm that this URL works if requested directly, it's just another simple published website on local network). So it reported a matched pattern, but still the page shows 404, whereas I expected it to return the content from the rewritten url (which should be http://10.0.0.5/index - I confirm that this URL works if requested directly,它只是本地网络上另一个简单的已发布网站)。 I don't even know if this is possible now or I did something wrong here.我什至不知道现在这是否可能,或者我在这里做错了什么。

URL rewrite inbound rule get executed before controller action.It is appreciated if you could post full error message in your Failed request tracing log. URL 重写入站规则在 controller 操作之前执行。如果您可以在失败的请求跟踪日志中发布完整的错误消息,我们将不胜感激。

If the request http://10.0.0.5/index but return 404 from IIS.如果请求http://10.0.0.5/index但从 IIS 返回 404。 It sounds like your ARR proxy was not enabled at all.听起来您的 ARR 代理根本没有启用。 First of all, please try to disable reverse proxy outbound rule.首先,请尝试禁用反向代理出站规则。 Then go to IIS manager->server node->application request routing cache->Server proxy setting->Enable proxy.然后go到IIS管理器->服务器节点->应用请求路由缓存->服务器代理设置->启用代理。

Update:更新:

The rewrite rule has worked and it seems that the request was stopped by重写规则有效,似乎请求被停止了

[HttpException]: The controller for path '/questions/62078944/iis-url-rewrite-not-working-the-input-url-not-even-captured' was not found or does not implement IController. [HttpException]:未找到路径“/questions/62078944/iis-url-rewrite-not-working-the-input-url-not-even-captured”的 controller 或未实现 IController。 at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->" at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext , AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step , Boolean & completedSynchronously) -->"

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

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