繁体   English   中英

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

[英]IIS URL rewrite not working, the input URL 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对其进行测试,以便将其重写为目标 url 并显示从那里返回的内容,而不是显示 404)。

我的 URL 重写规则使用Reverse Proxy模板。

我希望我在这里的理解是正确的。 我该如何诊断? 我的目的只是通过捕获通过我的网站的所有请求来将 IIS 转换为反向代理,在请求重写的 URL 并将内容返回给原始客户端之前检查是否有任何匹配定义的正则表达式模式。

更新

对于那些可能不了解 ASP.NET MVC 的人:

假设我的网站有一个名为HomeController的 controller 带有操作Index ,并且映射到它的 URL 是/Home/Index

URL 我的意思是这里没有映射到任何动作可能是/Home/TestProxy这里HomeController没有公开任何动作TestProxy也没有任何路由规则映射/Home/TestProxy到任何动作。 因此,在这种情况下,ASP.NET MVC 应用程序将显示404页面。

如上所述,对于映射到有效 controller 操作的 URL,它们似乎被捕获并视为输入 URL (在根据重写规则检查之前)。 但是对于未映射到任何 controller 操作(显示 404)的 URL,我看不到任何记录为输入 URL(因此,它们当然不会根据重写规则进行检查,也不会起作用)。

更新 2

实际上,我测试的 URL 甚至没有映射到 controller 所以看起来它没有被我设置的失败请求跟踪规则记录。 现在我尝试使用映射到 controller 的 URL 但没有任何操作(它仍然显示 404),但成功地被“失败的请求跟踪”规则记录。 我可以在日志文件中看到这一点:

<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,它只是本地网络上另一个简单的已发布网站)。 我什至不知道现在这是否可能,或者我在这里做错了什么。

URL 重写入站规则在 controller 操作之前执行。如果您可以在失败的请求跟踪日志中发布完整的错误消息,我们将不胜感激。

如果请求http://10.0.0.5/index但从 IIS 返回 404。 听起来您的 ARR 代理根本没有启用。 首先,请尝试禁用反向代理出站规则。 然后go到IIS管理器->服务器节点->应用请求路由缓存->服务器代理设置->启用代理。

更新:

重写规则有效,似乎请求被停止了

[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) -->"

暂无
暂无

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

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